我想使用twitter api twitter + OAuth從我的iphone上分享圖像,但我不知道如何從我的iphone分享。我使用sharekit嘗試了相同的操作,但是我沒有獲得成功。你會告訴我如何使用twitter api在iphone上分享twitter上的圖片嗎?我怎樣才能發送圖像在我的iPhone在ios5的twitter上
3
A
回答
5
由zot提供的鏈接工作,但我不得不添加一些代碼,我必須添加兩個框架Twitter.framework和Account.framework。修改後的代碼如下
- (IBAction)sendCustomTweet:(id)sender {
// Create an account store object.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
UIImage *image =[UIImage imageNamed:@"Icon.png"];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"]
parameters:[NSDictionary dictionaryWithObject:@"Hello. This is a tweet." forKey:@"status"] requestMethod:TWRequestMethodPOST];
// "http://api.twitter.com/1/statuses/update.json"
[postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/png"];
// Set the account used to post the tweet.
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
[self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO];
}];
}
}
}];
}
+0
你有更新的iOS 9嗎? –
0
使用Sharekit共享圖像。
教程:How to Add Twitter Sharing to Your iPhone/iPad App Using ShareKit
1
你檢查了這一點:iOS 5 Attach photo to Twitter with Twitter API
這隻適用於iOS5的手機。
在我的應用程序中,這是iOS5以前的版本,我使用TwitPic上傳照片併發布Twitter狀態。有一個關於如何使用ASHttpRequest在這裏做Twitter的狀態更新一個很好的教程:如果你想追求這種方法讓我知道,因爲就是你需要做的,超出了本教程的額外工作
http://www.icodeblog.com/2009/07/09/integrating-twitter-into-your-applications/
你也需要從TwitPic獲得一個API密鑰。
相關問題
- 1. 我怎樣才能在圖
- 2. 我怎樣才能從Facebook的圖像
- 3. 我怎樣才能把滾動在我的iPhone視圖?
- 4. 我們怎樣才能在iPhone
- 5. 我怎樣才能發送文本?
- 6. 我怎樣才能使拇指圖像不裁剪在iPhone?
- 7. 我怎樣才能上傳在asp.net服務器端的圖像
- 8. 我怎樣才能在Android 4.0的上
- 9. 我怎樣才能在twitter上獲得過去的信息?
- 10. 我們怎樣才能在iPhone更快地上傳圖片
- 11. 我怎樣才能代表我在用戶的牆上發帖?
- 12. 我怎樣才能定位圖像
- 13. 我怎樣才能在我的課
- 14. 我怎樣才能在Ionic2
- 15. 我怎樣才能在Zebble
- 16. 我怎樣才能在PreferenceScreen
- 17. 我怎樣才能在vim
- 18. 我怎樣才能在Python
- 19. 我怎樣才能在VB.net
- 20. 我怎樣才能在DB2
- 21. 我怎樣才能在Java
- 22. 我怎樣才能在Python
- 23. 我怎樣才能在PAM
- 24. 我怎樣才能在JSP
- 25. 我怎樣才能在RSPEC
- 26. 我怎樣才能在logstash
- 27. 我怎樣才能在Doctrine2
- 28. 我怎樣才能在Python
- 29. 我怎樣才能在vb.net
- 30. 我怎樣才能在SAS
你只是想在twitter上分享你的圖片鏈接,或者你想先上傳圖片,然後獲取圖片鏈接,然後在twitter上上傳該鏈接。 – Gypsa
我要在twitter上發佈圖片 – iPhone