Easy Twitter & FaceBook sharing with ShareKit

I’ve had a few questions about how to implement Twitter & FaceBook sharing, so here’s how I did it.

ShareKit provides an easy drop-in solution for posting to Twitter, FaceBook, Instapaper, Tumbler, and many other services. However, in many cases you don’t need all of the features and simply want to post a status to FaceBook or Twitter.

It takes only two lines of code to simply share an item to Twitter, FaceBook, or most other supported services:

  1. Create a SHKItem with the text you want to post
  2. Call the shareItem: method of the appropriate subclass.

These are the specific methods for Twitter & FaceBook:


- (IBAction)tweet:(id)sender
{
    SHKItem *aTweet = [SHKItem text: @"Share this text"];
    [SHKTwitter shareItem:aTweet];
}

- (IBAction)facebook:(id)sender
{
    SHKItem *post = [SHKItem text: @"Share this text"];
    [SHKFacebook shareItem:post];
}

When you call shareItem: it will display the login & authentication prompt and show the item to be shared.

The most difficult part is setting up your application on Twitter or FaceBook with the correct permissions and obtaining the proper API keys. Read the instructions in SHKConfig.h carefully for details on how to set up your application and enter the API keys there.

I have my own branch of ShareKit at https://github.com/mike3k/ShareKit which fixes a problem related to iOS 5 and gets rid of most of the compiler warnings.

1 thought on “Easy Twitter & FaceBook sharing with ShareKit”

  1. Can anybody help me. I am new to sharekit and have a lil knowledge of objective C. So need some way out how can I retrieve my javascript variable in .m file in xcode.

    I am getting a newsFeed JSON object that contains a url and this url I need to pass to facebook share method so that I can make a post on Facebook. I will be thankful if somebody can illustrate this with an example.

    Thanks
    Prabhjot

    Reply

Leave a Comment