Quick & Dirty For Setting Up Using Twitter in Python

Let's say you want to post to your Twitter account from a command-line python script. Here are the quick a dirty steps to get up and running with twython. There is another description at the twython site but it isn't as basic as this.

  1. Install twython with:
    sudo pip install twython
  2. Register the application on Twitter
    1. go to https://dev.twitter.com/apps
    2. fill out the form and hit "Create your Twitter application"
  3. From the App "Details" tab, click "modify app permissions" and change  to "Read and Write" (it'll take a few minutes for that to be reflected on the app details page.
  4. Go get your API Keys
    1. Click on the "API Keys" tab from the Application Detail page
    2. Copy the API key
  5. In a terminal window:
    1. fire up the python interpreter
    2. import the modules you need:
      from twython import Twython, TwythonError
    3. make a variable for your API key:
      APP_KEY = 
      and have it equal the thing you copied from the Twitter site using single quotation marks around it.
  6. Switch back to the Twitter API Key browser page:
    1. Copy the API Secret key
  7. Switch back to terminal running the python interpreter:
    1. make a variable for your API secret:
      APP_SECRET =
      and have it equal the thing you copied from the Twitter site using single quotation marks around it. 
    2. use twython to get a object by entering the following in the python interpreter:
      twitter
      = Twython(APP_KEY, APP_SECRET)
    3. then an auth object:
      auth = twitter.get_authentication_tokens()
  8. Still in the python interpreter, grab the oauth url copying the URL you see when you type:
    auth['auth_url']
  9. Past the URL into a browser, sign into your account on Twitter if prompted and click "Authorize App." You should get a code, copy that code into your python interpreter window as a variable for the PIN
    PIN = 
    1. create a variable with the AUTH TOKEN
      AUTH_TOKEN=auth['oauth_token']
    2. create a variable with the AUTH SECRET
      AUTH_SECRET=auth['oauth_token_secret']
  10. Then, in the interpreter, reconnect to Twitter and get the final authorization tokens with the PIN number that you set earlier:
    twitter = Twython(APP_KEY, APP_SECRET, auth['oauth_token'], auth['oauth_token_secret'])
    final_step
    = twitter.get_authorized_tokens(PIN)
  11. then look at final_step['oauth_token'] and final_step['oauth_token_secret'] and save them somewhere in the configuration of your app. Also be sure to copy the original APP Key and APP Secret to a variable in your app. Below I use APP_KEY, APP_SECRET, OAUTH_TOKEN and OAUTH_TOKEN_SECRET
  12. Once you are all done you can use this code in an app to test it:
    from twython import Twython, TwythonError

    APP_KEY =
    [the thing you copied from earlier in single quotes]
    APP_SECRET =
    [the thing you copied from earlier in single quotes]
    OAUTH_TOKEN =
    [the thing you copied from earlier in single quotes]
    OAUTH_TOKEN_SECRET =
    [the thing you copied from earlier in single quotes]

    # Requires Authentication as of Twitter API v1.1
    twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

    try:
        twitter.update_status(status='Just a test, please ignore')
    except TwythonError as e:

        print e
     

PS I now use Tweepy instead of Twython but all of this is similar there.

Banking Advertising



William Borsody, Financial Advertising, 1909

LAMAS Architecture

Recently got to hang out with my brother, James Macgillivray, and catch up on his and his wife's architecture firm, LAMAS. Really cool stuff he and Wei-han Vivian Lee are up too. Plus the LAMAS (Lee and Macgillivray Architecture Studio) site is cool as well and showcases a bunch of their work. Amazing to see what they have already built and looking forward to seeing what they will build in the future.

Google Ngram Viewer Now In "Define"

I've always found Google's definitions to be useful but yesterday I noticed they had added something useful from Google Books to their definitions: understanding a word's usage over time.

For example, a search for "define Twitter" yields:


If you expand the definition by clicking on the big downward arrow, you see a bunch of additional information including this chart of the uses of "Twitter" over time:


Google is drawing on mentions of these words in the corpus of books it has scanned as part of the Google Books project, which I had the privilege of working on while at Google. Indeed this is really just a more visible way of exposing the phenomenal Ngram viewer that Google has improved over the last few years. The Ngram viewer can be used to compare word frequencies and do lots of other interesting stuff. The database of word frequencies over time is also available to the public under the Creative Commons Attribution 3.0 Unported License so that others can build on the data. Here is a view of Twitter versus Tweet in the Ngram Viewer:



Anyhow, this may not be new to the world but it was new to me and is way cool. As the Google Books legal cases continue, it is also another great example of the value of the initiative to the public. 

PS Two more I couldn't resist adding. Good luck not spending the next half hour doing your own.



Update: And yes, there are many flaws with relying on the Ngram data to prove a point without further analysis. For examples, see Robusto's discussion on StackExchange. 




Some News and Thanks

I will soon pass the Twitter General Counsel torch to Vijaya Gadde (@vijaya). Vijaya has been managing Twitter’s corporate and international legal work, and I’ve gotten to know her well over the last fourteen years. I couldn’t be happier with her appointment as General Counsel of Twitter.


As we transition, I will dial back my day to day involvement with Twitter. I’ll continue to support the company and its great people by staying on as an advisor for the legal, trust & safety, corporate development and public policy teams. I continue to care deeply about Twitter, the folks who work at Twitter and our tremendous users, so I’ll remain close to all three.


It has been a joy to work at Twitter. I have been fortunate to support the multiple award winning trust, public policy, corporate development, legal and, at various times during my tenure, communications and trust engineering teams. These are phenomenal teams made up of great people. I also continue to be awestruck by the many, varied, incredible ways people use Twitter.


I am proud to have worked with colleagues who defend and respect the user’s voice; who push freedom of expression and transparency; and who innovate and lead. Together we’ve brought some incredible products and talent into Twitter. We’ve supported teams creating new businesses and pushing to reach every person on the planet. Twitter continues to employ some of the funniest, most generous, smart, passionate and humble people I’ve ever met. I was lucky to get to work with them, and you can too.


To my teams, all the folks who work at Twitter and Twitter users: Thank you. I can’t wait to see what you do together next.


As for me, it has been my privilege to work and fight on behalf of great companies and their users over the last decade. A privilege and a lot of work. So, I’m looking forward to engaging my various internet passions from new and different perspectives, seeing friends and family without distraction, and just goofing off a bit. We should all do more of that.


More to come here and at @amac.

Public Domain Images courtesy of Google Books, sourcing here and here.

Pericrocotus


A beautiful bird I had never heard of, the Pericrocotus. From The Illustrated Natural History: Birds, p. 368.

Overbroad Censorship & Users

A lot of good stuff has been written about why the currently pending Stop Online Piracy Act (SOPA) is bad for the future of the internet, the technology industry, international human rights, security, free speech [pdf], privacy, blind people and jobs. One thing I haven’t seen is a succinct description of the problems of site-wide censorship when it comes to ordinary, non-infringing users. So... I’ll try to do that here.

SOPA’s unit of analysis is a “site or portion thereof” See Section 102(a). By contrast, if a portion of a site is infringing, SOPA’s unit of censorship is everything at the domain name. See Section 101(17), 102(c)(2)(B) and 102(c)(2)(A).

The harm that does to ordinary, non-infringing users is best described via a hypothetical user: Abe. Abe has never even so much as breathed on a company’s copyright but he does many of the things typical of Internet users today. He stores the photos of his children, now three and six years old, online at PickUpShelf* so that he doesn’t have to worry about maintaining backups. He is a teacher and keeps copies of his classes accessible for his students via another service called SunStream that makes streaming audio and video easy. He engages frequently in conversation in several online communities and has developed a hard-won reputation and following on a discussion host called SpeakFree. And, of course, he has a blog called “Abe’s Truths” that is hosted on a site called NewLeaflet. He has never infringed on any copyright and each of the entities charged with enforcing SOPA know that he hasn’t.

And yet, none of that matters. Under SOPA, every single one of the services that Abe uses can be obliterated from his view without him having any remedy. Abe may wake up one morning and not be able to access any of his photos of his children. Neither he, nor his students, would be able to access any of his lectures. His trove of smart online discussions would likewise evaporate and he wouldn’t even be able to complain about it on his blog. And, in every case, he has absolutely no power to try to regain access. That may sound far-fetched but under SOPA, all that needs to happen for this scenario to come true is for the Attorney General to decide that some part of PickUpShelf, SunStream, SpeakFree and NewLeaflet would be copyright infringement in the US. If a court agrees, and with no guarantee of an adversarial proceeding that seems very likely, the entire site is “disappeared” from the US internet. When that happens Abe has NO remedy. None. No way of getting the photos of his kids other than leaving the United States for a country that doesn’t have overly broad censorship laws.

There are millions of US internet users just like Abe. If you are one of them, I urge you to make your voice heard by going to AmericanCensorship.org or EngineAdvocacy.org/voice.

* All names of services meant to be fictitious.


Images are public domain, sourcing here.

RightsCon 2011 Images

Here are a set of images I used during my SV Human Rights Conference presentation along with the attribution for each.

Fight between Rioters and Militia, from Pen and Pencil Sketches of the Great Riots.
The Frame, from Typographia.
Printing Press, from  Typographia.

 
 Ocellated Mound-builder (Liepoa ocellata), from Birds: The elements of ornithology.