Skip to content

brackendev/TwitterSDK-Pharo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TwitterSDK-Pharo

Interact with the Twitter API v1.1 on Pharo.

Installation

  1. If you do not have a Twitter app set up:
    1. Sign in to Twitter and go to https://developer.twitter.com/ to create an app.
    2. Retrieve the app API key, API key secret, access token, and access token secret.
  2. Load this project in Pharo. In a Playground, Do it:
Metacello new 
  repository: 'github://brackendev/TwitterSDK-Pharo/src';
  baseline: 'TwitterSDK';
  load.

Example Usage

twitterSDK := TwitterSDK createWithAPIKey: API_KEY apiKeySecret: API_KEY_SECRET accessToken: ACCESS_TOKEN accessTokenSecret: ACCESS_SECRET.
"Follow @brackendev"
parameters := Dictionary newFrom: {'screen_name' -> 'brackendev'}.
twitterSDK postPathSegment: 'friendships/create.json' parameters: parameters.
"Post a Tweet with an image"
"Note: The image resides in the Pharo image root directory"
mediaUpload := TwitterSDKTools mediaUploadFile: 'test.jpg' additionalOwners: nil twitterSDK: twitterSDK.
mediaID := (mediaUpload at: 'media_id') asString.
parameters := Dictionary newFrom: {('status' -> 'Test tweet'). ('media_ids' -> mediaID)}.
twitterSDK postPathSegment: 'statuses/update.json' parameters: parameters.

"...or"
TwitterSDKTools postTweetStatus: 'Test tweet' image: 'test.jpg' twitterSDK: twitterSDK.
"Retrieve a Tweet"
parameters := Dictionary newFrom: {('id' -> '1178944243106242560')}.
tweet := (twitterSDK getPathSegment: 'statuses/lookup.json' parameters: parameters) last.

"...or"
tweet := TwitterSDKTools retrieveTweetForID: '1178944243106242560' twitterSDK: twitterSDK.
"Retrieve a Tweet's text"
parameters := Dictionary newFrom: {('id' -> '1178944243106242560')}.
tweet := (twitterSDK getPathSegment: 'statuses/lookup.json' parameters: parameters) last.
text := tweet at: 'text'.

"...or"
text := TwitterSDKTools textForTweetID: '1178944243106242560' twitterSDK: twitterSDK.
"Retrieve a Tweet's media URLs"
tweet := TwitterSDKTools retrieveTweetForID: '1206776380844838914' twitterSDK: twitterSDK.
mediaURLs := TwitterSDKTools mediaURLsForTweet: tweet.

"...and inspect it"
mediaURL := mediaURLs first.
(ImageReadWriter formFromStream: (ZnEasy get: mediaURL) contents readStream) asMorph inspect.

Author

Bracken Spencer

License

TwitterSDK-Pharo is released under the MIT license. See the LICENSE file for more info.