开发者

Twitter + OAuth for tweets with images

Is it pos开发者_Python百科sible to now upload images in tweets through the iPhone? If so, how is this done using Twitter + Oauth?


In iOS5 you can use Apple's twitter framework, specifically the TWTweetComposeViewController class.

Alloc and init a TWTweetComposeViewController object, and then use the addImage:(UIImage*)image method before presenting the compose view to the user, eg:

TWTweetComposeViewController *tweetComposer = [[TWTweetComposeViewController alloc] init];
[tweetComposer addImage:someImage];
[tweetComposer setInitialText:@"Tweet about this image"];
[self presentModalViewController:tweetComposer animated:YES]; // Assuming this in a UIViewController subclass 
[tweetComposer release];

The methods addImage: and setInitialText: return a BOOL, YES if the image/text was added successfully, and NO if it couldn't be added, eg if you add image/text after presenting the TWTweetComposeViewController, or it makes the tweet longer than 140 characters.

The image uploading is all done for you, you just have to supply the image data as a UIImage

The downside to this is it requires the user to have registered their twitter account with the device, but if they haven't it will prompt them to. And it only works on ios5 and above, so no IPhone 3G, or iPod touch 2G support.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜