On a balmy evening in April 2009 Barham Salih, then deputy prime minister of Iraq, sat in the garden of his Baghdad villa while a young internet entrepreneur called Jack Dorsey tried to persuade him that he needed to be on Twitter. Dorsey, the founder of Twitter, was in Baghdad at the invitation of the State Department. Over the previous three days, he and eight other Silicon Valley bigwigs, kitted out with helmets and flak jackets, had been bundled around Baghdad in an armoured convoy, meeting anyone there was to meet. They’d been introduced to the prime minister’s council of advisers, glad-handed the Iraqi Investment National Commission and spoken to a group of engineering students from Baghdad University; they’d even had time to fit in a visit to the Iraqi National Museum. Among them were several high-ranking engineers from Google, the founder of the community organising tool Meetup, a vice-president of the firm behind the blogging platform WordPress, and an executive from Blue State Digital, the internet strategy firm that had done a fair bit to help Obama to the presidency the previous November.

The person getting all the attention was Dorsey, because by then Twitter was all anyone wanted to talk about. In fact one reason we know so much about the trip is that Dorsey and his colleagues spent much of their time tweeting about it, sending news of their journey in electronic haiku to their followers back home. ‘Lots of helicopters,’ Dorsey observed on his Twitter feed: ‘Met the president of Iraq. Amazing palace.’ In another tweet, he tells his followers that he’s been ‘talking to Iraqis to figure out if technologies like Twitter can help bring transparency, accessibility and stability to the area’. When he finds a wi-fi network in the presidential palace, he says how happy he is to be back online: ‘Catching up on the rest of the world.’ ‘Lots going on out there!’ he writes. Barham Salih’s inaugural tweet was less upbeat: ‘Sorry, my first tweet not pleasant; dust storm in Baghdad today & yet another suicide bomb. Awful reminder that it is not yet all fine here.’

This was the first time the US government had organised a new media delegation to a country in the Middle East. The idea was to introduce the minds behind America’s internet start-ups to the movers and shakers who were going to rebuild Iraq, but as Dorsey’s excitable tweets indicated, the audience back home was just as important. The trip’s architect was a 27-year-old State Department wunderkind called Jared Cohen. He shepherded the techies around Baghdad and explained the thinking behind the whole venture at a video-link press conference with journalists back in Washington:

You know, historically, we’ve thought about new technology as a tool primarily for communication. But more and more, we’re looking at, how do we leverage new technology to support broader policy objectives, you know, whether it’s civic empowerment, whether it’s capacity building, whether it’s promotion of accountability and transparency, and so forth. So logically, in looking at these two concepts, we started reaching out to Silicon Valley, or the larger technology industry.

Some of the journalists wanted to know how all this new technology was going to help a country that couldn’t guarantee its citizens round-the-clock electricity, but Cohen stood his ground. One reason for the huge take-up of mobile phones in Iraq, he pointed out, was the worsening security situation: people needed to keep track of friends and loved ones, to make sure they were still in one piece. As for using America’s technological expertise as a diplomatic tool: that, Cohen believed, was a no-brainer. ‘At the end of the day, the platforms that all of these guys here are pushing out from the tech industry are riddled with American values of critical thinking, free flow of information, freedom of choice, freedom of assembly.’ ‘Wow, my God, they have a lot of Kool-Aid over there, don’t they?’ a journalist said at the end of the press conference.

The high-tech Kool-Aid had been brewing at the State Department since Cohen’s arrival some years before. Condoleezza Rice had spotted him first. He had impressed her by inveigling his way in to meet her when she was national security adviser, and in 2006 she snapped him up for the State Department – the youngest ever member of its policy planning team. He was only 24, and his job was to advise on how to use social media to advance America’s interests in the Middle East, especially among the young. It helped that he’d actually been there. While at Oxford on a Rhodes Scholarship, he had used the pretext of his postgraduate research to travel widely throughout the region. His book Children of Jihad, published two years after he began working at the State Department, recounts his brushes with danger in the style of a Famous Five novel. In Beirut he befriends some Hizbullah supporters at a McDonald’s; in Tehran he manages to get himself invited to underground parties (‘I’m not generally a big drinker, but who could resist the opportunity to booze it up when the mullahs weren’t looking?’); in Syria he falls asleep in the back of a cab and wakes up in Iraq. And all the time he’s asking questions, sometimes out loud. In Lebanon he hands out a survey: ‘In one sentence, if the United States could change anything to gain the support of the youth, what should it do?’ The answers aren’t encouraging: one young Lebanese reports that ‘America is the biggest imperialist and the only thing I want is to see America destroyed.’ Before long his new Hizbullah friends begin to wonder about his motives, and stop inviting him to McDonald’s. ‘They became totally unresponsive,’ Cohen remembers, ‘and I began to wonder why.’

Children of Jihad is written with the exuberance of a hipster on his year off, but it isn’t stupid. The young people Cohen encounters have little faith in the authoritarian regimes that govern them, but they also remind him that Western military intervention would only make things worse. His experiences leave Cohen with firm convictions on how to foment change in the Middle East. ‘The youth can only be understood as their own phenomenon,’ he says:

They are far more tolerant than older generations and seemingly more sophisticated … The internet is their democratic society. Even though the internet is monitored, the youth have become extremely sophisticated in getting around the surveillance. They have become digital revolutionaries, creating, participating in, and popularising chat rooms, blogs and forums for discussion about everything from sports to politics.

His book ends with a rallying cry: ‘Young people in the Middle East are reachable – and they could be waiting to hear from us.’

Cohen’s arrival at the State Department coincided with a fresh outburst of hostilities between the Bush administration and Iran, and one consequence was that the State Department was granted $75 million to disseminate propaganda and help elements hostile to the Iranian regime. But then it became clear that simply throwing money around was making America more enemies than friends. Meanwhile, away from the public sabre-rattling, Cohen was building bridges with big internet companies like YouTube and Twitter, making allies by arguing for the cause of social media and generally getting a sense of what was possible. He was also making friends on Facebook. At the beginning of 2008, a Colombian Facebook group called ‘One million voices against FARC’ sprang up in Barranquilla to campaign against the guerrillas; the computer technician behind it was surprised to receive a message from Cohen, asking if he could pay him a visit.

A few weeks after Obama’s victory, James Glassman, another Bush-era official at the State Department, delivered a lecture at the New America Foundation in which he made much of the internet. Glassman had been to Bogotá with Cohen, and began by telling the story of the One Million Voices campaign. Attempts to engage with foreign citizens used to mean thinking up educational and cultural schemes to get America’s side of the story across, he said, but that sort of thing was now out of date. ‘We have arrived at the view that the best way to achieve our goals in public diplomacy is through a new approach to communicating, an approach that is made far easier because of the emergence of Web 2.0, or social networking technologies. We call our new approach Public Diplomacy 2.0.’

Public Diplomacy 2.0 was more than a technology: it was ‘a holistic approach, an attitude’. What’s more, it was already happening. ‘Our Digital Outreach Team goes onto blogs and websites. In Arabic, Farsi, Urdu, and we hope soon in Russian, its members identify themselves as State Department representatives. They engage in the conversation, gently inform, correct distortions about US policies.’ America’s terrorist enemies were no match for all this interactivity. ‘Extremists can’t adapt to social networking because it shakes the foundations of their whacked out, rigid ideology.’ (By then, though, the ideology of the Bush administration was looking a little whacked out too.)

To the incoming secretary of state, Hillary Clinton, and her senior advisers the idea of doing foreign policy on Facebook threw up intriguing possibilities. Stripped of its air of gung-ho propagandising and reworked as a campaign for internet freedom in places like Iran, American outreach would sit very nicely with Obama’s campaign pledge to put a friendlier face on American power. Cohen, who by then was championing Facebook as ‘one of the most organic tools for democracy promotion’, was just the man. Not only was he allowed to keep his job: he was made chair of a new working group on the internet. In May 2009 the new approach was given its first major public outing, and a fresh lick of paint. ‘Twenty-first-century statecraft’, Hillary Clinton said in a series of choreographed speeches, was about using the internet to work from the ‘bottom up’: it was less about telling people what to think than about encouraging them to stand up for their right to talk among themselves and, if they wished, to the United States. Just as America’s Cold Warriors had used Radio Free Europe and the Congress for Cultural Freedom to tear down the Berlin Wall, the campaign for internet freedom could help tear down the firewalls authoritarian regimes have erected around their populations, and throw a lifeline to the dissidents inside.

There were reasons for thinking that something was afoot. In April last year thousands of protesters took to the streets in Chisinau, the capital of Moldova, to complain about vote-rigging; observers noticed that some were using Twitter, and the revolt was dubbed ‘the Twitter revolution’. Two months later, after a disputed presidential election on 12 June, hundreds of thousands of Iranians poured onto the streets of Tehran and other cities in support of Mir Hossein Mousavi, one of the defeated candidates. For some days the government-controlled media pretended nothing much was happening. Twitter and other social networking sites, on the other hand, were buzzing with news of upcoming rallies; events were being analysed as they happened and, during the crackdown, anyone with a mobile phone could see shocking images of the brutality meted out by the police and the Basij militia. In a series of blog posts fired off within hours of the first demonstrations, the Atlantic’s Andrew Sullivan proclaimed Twitter ‘the critical tool for organising the resistance in Iran’. In a piece of electronic agitprop he declared that ‘the revolution will be twittered.’ The technophiles in Washington didn’t disagree.

One of the most vocal enthusiasts of the new developments was a teacher of interactive telecommunications at NYU called Clay Shirky. Shirky is a witty and engaging writer. His book Here Comes Everybody: How Change Happens when People Come Together had been published not long before, and in the theology of internet evangelism it was already considered a foundational text. Here Comes Everybody is full of stories that make collective action sound like a marvellous wheeze: the woman who lost her mobile in the back of a taxi and used the internet to get it back, the 100 young New Yorkers who were persuaded by an anonymous email to converge on Macy’s department store and stare in silence together at an expensive rug.

Shirky argued that the internet had opened up the possibility of an exciting new form of leaderless social co-ordination. From now on, he said, blogging and online social networking were going to be central to political liberty. ‘To speak online is to publish, and to publish online is to connect with others. With the arrival of globally accessible publishing, freedom of speech is now freedom of the press, and freedom of the press is freedom of assembly.’ Taking the example of a group of Belarusian activists who’d outflanked the secret police by organising their demo on a blog, Shirky predicted that the internet would prove especially useful in countries where the government keeps a tight rein on the means of communication, because dissidents could use it to give the authorities the slip. ‘The government can’t intercept the group members in advance, because there is no group in advance.’ Earlier in June Shirky had topped the bill at a techno-boosterish TED (Technology, Entertainment and Design) conference at the State Department. ‘This is it,’ he said as events unfolded in Iran. ‘The big one. This is the first revolution that has been catapulted onto a global stage and transformed by social media.’

From his office in the State Department Cohen, too, was keeping a close eye on the flood of Iran-related tweets. On Monday 15 June, as the post-election protests gathered pace and a massive rally was held to support him, Mousavi alerted his followers on Twitter that the social networking site was about to carry out a routine shutdown to overhaul its system. Cohen, who was already working closely with Jack Dorsey, emailed him directly to suggest delaying the upgrade. Twitter complied, announcing on its website that because of ‘the role Twitter is currently playing as an important communication tool in Iran’ it was putting off its scheduled system maintenance until Tuesday afternoon, when it would be the middle of the night in Tehran.

Cohen’s email wasn’t well timed. Earlier that month Obama had delivered his Cairo speech, in which he admitted the CIA’s role in overthrowing Iran’s democratic government in 1953. On the day the New York Times broke the story of Cohen’s email, Obama said that, given the history of relations between the two countries, America could not be seen to be ‘meddling in Iranian elections’. At a press conference a State Department official denied that Cohen’s move amounted to meddling and played down its significance. ‘This is completely consistent with our national policy,’ he said. ‘We are proponents of freedom of expression.’ Whether or not Cohen wrong-footed his superiors, his intervention did his cause no harm. In July the US Senate authorised a fund of $20 million to build websites and software to help Iranians share and receive information under the radar of their government.

Obama too seemed to warm to the internet as a tool for geo-politicking. In a speech to Chinese students in November, he answered a planted question about internet censorship (it was submitted via the US Embassy website and asked by the US ambassador): ‘I think that the more freely information flows, the stronger the society becomes, because then citizens of countries around the world can call their own government to account.’ In January this year Google announced that hackers had tried to break into the Gmail accounts of Chinese dissidents, and that it was considering withdrawing from the country altogether. Google’s decision came a few days after Cohen had brought another delegation, including Dorsey and Google’s CEO, Eric Schmidt, to Washington for a private dinner with Hillary Clinton and her staff. A week later Clinton spoke out even more strongly in defence of internet freedom and the role of the Obama administration in securing it. Seconding Obama’s warning to the Chinese, she argued that new tools and fresh policies were needed ‘to develop our capacity for what we call at the State Department 21st-century statecraft’; announced an initiative to help activists dodge internet surveillance; and urged American companies to take the lead in challenging foreign governments’ demands for censorship. ‘The freedom to connect,’ she said, ‘is like the freedom of assembly, only in cyberspace. It allows individuals to get online, come together, and hopefully co-operate.’ Twenty-first-century freedom, if it was going to mean anything, was going to mean the freedom to use Twitter.

Does Twitter have the power that is claimed for it? Some evidence from the contested Iranian election is presented in Death to the Dictator!, the first book-length account of the activist movement’s rise and fall. The book claims to be the work of an Iranian journalist writing under a pseudonym, and it mostly describes the experience of an (also pseudonymous) young man from Tehran who is swept up in the excitement and then arrested and tortured by the Basij militia. What starts out as a campaign alleging electoral fraud in support of a defeated politician quickly spirals into something more interesting: a chaotic uprising against the clerics and the Revolutionary Guards which, had it continued to spread and gather momentum, might have threatened the foundations of the Islamic Republic. Social media, however, play a minor role in Afsaneh Moqadam’s story, and an ambiguous one. At first the protesters are happy to use their mobiles to let each other know about upcoming rallies, and to share images of the demonstrations on YouTube. Soon, however, they grow wary of the rush of information. ‘Cellphone cameras, Facebook, Twitter, the satellite stations,’ the anonymous narrator complains: ‘The media are supposed to reflect what is going on, but they seem, in fact, to be making everything happen much faster. There’s no time to argue what it all means.’ Many come to believe that Western mobile phone companies have supplied the Iranian government with software to enable them to eavesdrop on their conversations. Some even fear that their mobiles have become bugging devices.

Before long the protagonist is urging his fellow activists not to bring their mobiles on demonstrations – if they lose them or drop them, they will be traced back to their owners. On one of the later demos, he notices someone surreptitiously taking pictures of himself and his fellow demonstrators on his mobile phone. Then he sees a photo of himself on a pro-government website that is soliciting help in identifying the troublemakers – a novel application of what internet gurus call ‘crowdsourcing’. It’s only after the crackdown on 20 June that the protesters retreat to their apartments to spend hours on the internet, sharing anti-filtering software and searching for scraps of news on Facebook, YouTube and reformist websites. And it’s now that the authorities clamp down hard: the internet is often blocked or so slow that it almost comes to a halt and the mobile network is often switched off, making it impossible to send texts. When service is finally restored, one semi-serious suggestion passed around among the activists is that they abandon the entire medium: ‘Boycott SMSs! That will cost the telecoms a packet!’

If Death to the Dictator! has little time for Twitter, that’s hardly surprising. When you look at the figures you realise that only a very small number of Iranians were using it. In 2009, according to a firm called Sysomos which analyses social media, there were 19,235 Twitter accounts in Iran – 0.03 per cent of the population. Researchers at al-Jazeera found only 60 Twitter accounts active in Tehran at the time of the demonstrations, which fell to six after the crackdown. There’s certainly a growing internet culture in Iran – in Blogistan, the media academics Annabelle Sreberny and Gholam Khiabany estimate that there are about 70,000 active blogs in the country, including a vibrant gay blogosphere – but it’s far from being the preserve of liberal reformists. Ahmadinejad’s supporters used Facebook and Twitter to spread his campaign messages while, on the other side, someone set up a Facebook group called ‘I bet I can find 1 million people who dislike Ahmadinejad’ (it had attracted 26,000 followers by April 2010). There’s little evidence, however, that any of this internet activity fuelled the street demonstrations; most were organised by word of mouth and text messages sent to friends. But the internet helped protesters bypass the state media and, for the few information-hungry Iranians who had it, Twitter allowed news to be sent out of the country when the authorities were blocking the mobile network. Even here, however, the global solidarity it bought for their cause might well have distracted them from the real work of reaching out to their fellow citizens.

It was more useful for the global media. ‘Twitter functioned mainly as a huge echo chamber of solidarity messages from global voices, that simply slowed the general speed of traffic,’ the authors of Blogistan conclude. On 16 June the authorities forbade journalists from covering the demonstrations without permission. Kicking their heels in their hotel rooms, most foreign correspondents began surfing through the blizzard of tweets and video clips to try and work out what was going on. But it was all difficult to verify, and a good part was tweeted from outside the country: to add to the chaos, many overseas sympathisers had changed their location to make it look as if they were in Iran. The point – perhaps – was to confuse the Iranian authorities by opening the information gates, but the flood of unverifiable tweets may have confused the protesters too. Some of what was sent around on Twitter – the news, for example, that Mousavi had been arrested – simply wasn’t true, so the movement’s high-profile foreign supporters were often retweeting rumour and disinformation from the comfort of their desktops. ‘Here, there is lots of buzz,’ the owner of a US-based activist site told the Washington Post. ‘But once you look … you see most of it is Americans tweeting among themselves.’

The Iranian protesters had every reason to be paranoid about the internet. While some demonstrators were busy drumming up virtual support from the outside world, the police were scanning social networking sites to round them up. According to Evgeny Morozov, the Iranian authorities and their allies were quick to get into the swing, and were soon flooding mobile networks and the internet with false information and videos of dubious authenticity as a way of intimidating, dividing or demoralising the opposition. ‘Dear citizen,’ one cheery text sent to known protesters began, ‘according to received information, you have been influenced by the destabilising propaganda which the media affiliated with foreign countries have been disseminating.’ Morozov, an alumnus of George Soros’s Open Society Institute who blogs for Foreign Policy magazine, knows from his native Belarus that electronic activism doesn’t necessarily blow the doors off repressive regimes. Even if the authorities lose their monopoly on the flow of information, he shows in The Net Delusion, they gain access to a new kind of social control: the ability to manipulate the flow, and ear-wig at the other end. Regime loyalists can be called on to post propaganda of their own; the Kremlin has cultivated a whole school of young bloggers to propagate conspiracies about supposed threats to Russian sovereignty.

And it’s now cheaper than ever for authoritarian regimes to keep an eye on what their citizens are up to. In an interview with the Financial Times in 2009, a marketing manager for a Chinese data-mining firm claimed that the Chinese authorities have been able to cut the size of their internet monitoring staff by a factor of ten thanks to efficiency savings. ‘In the past, the KGB resorted to torture to learn of connections between activists,’ Morozov says. ‘Today, they simply need to get on Facebook.’ Since members of social networks can remain anonymous, Morozov notes, it would be unwise to use them to organise a semi-secret demo. The problem for the demonstrators in Tehran was that their movement lacked any clear direction beyond its demand that the election be annulled. The invention of a new kind of networked, shiftless, leaderless, just-in-time disorganised organisation didn’t seem to help. In the late 1990s Alan Greenspan ridiculed the fashionable notion that the dot-com economy could overturn the traditional laws of economic profit and loss: he called it ‘irrational exuberance’. There is now an irrational exuberance about the potential of social media: it’s as if online social networking could rescue the media, restore democracy and liberate the wretched of the earth, one tweet at a time.

But why did so many people want Twitter to win? For the US, bogged down in Iraq and Afghanistan, it’s easy to see the attraction. With the neoconservative plan to export freedom and democracy to the Middle East in ruins, it was cheaper and more subtle for the State Department to rally around the cause of internet freedom – to send in what Morozov calls the ‘cyber-cons’. At some point, however, the rhetoric of internet freedom led to the shakier proposition that citizens of authoritarian regimes could win their freedom by doing no more than getting together on the net.

The dangers of encouraging activists to rely on technology were vividly illustrated when a State Department plan to help Iranian dissidents outwit the police by distributing anti-surveillance software backfired. The software was called Haystack, and last March the State Department granted it a rare licence enabling it to be exported to Iran; since Haystack was the only software of its kind to be afforded such a licence, this amounted to an official seal of approval. Then it was discovered to be wholly unsafe – ‘the worst piece of software I have ever had the displeasure of ripping apart’, according to the computer security expert Morozov consulted. Amid mounting criticism of their efforts, some of it from Iranian dissidents, the people behind Haystack finally threw up their hands in September and admitted the weaknesses of their system (its leading developer signed off with a tweet: ‘A whirlwind is coming straight for me … I flee’). In the propaganda war inside Iran, episodes like this give the government a valuable weapon. For big American internet companies like Google and Twitter, the danger is that their interests come to be too closely defined with those of the American government: that they’re seen to be smuggling in statecraft under the guise of delivering technology. In the conspiracy mills of the Middle East, campaigns for internet freedom are denounced as cover for America’s broader agenda, the stalking horse for a shady new military-Twitter complex.

None of this seems to have blunted the State Department’s enthusiasm for its new approach, and the status and the visibility of bureaucrats like Jared Cohen has been greatly enhanced. Since that initial visit to Iraq, Cohen and his colleague Alec Ross, who worked on Obama’s presidential campaign, have led a series of technology delegations to any number of countries – among them, Afghanistan, Mexico and Russia. In between, they’re busy tweeting. With their backslapping banter punctuated with words like ‘dude’ and ‘awesome’, the pair come across as the Bill and Ted of 21st-century statecraft, on an excellent adventure to bring the wonders of social media to the rest of the world. Leading a contingent to Syria in June, Cohen tweeted: ‘I’m not kidding when I say I just had the greatest frappuccino ever at Kalamoun University north of Damascus’; later, Ross updated his Twitter feed with the news that Cohen had challenged the Syrian telecoms minister to a cake-eating competition. This is popular stuff, enough to have turned the pair into mini-celebrities in the world of Twitter: Cohen has more than 300,000 followers. On 100 consecutive days earlier this year, he took the trouble to tweet reminders of the 100 most heinous days of the Rwandan genocide. In September Google announced that it had head-hunted him from the State Department to run its new geopolitical think-tank, Google Ideas. The revolt of the geeks has only just begun.