我目前正在開發iOS應用程序,該應用程序從流API獲取一些推文。出於這個原因,我把用戶的用戶名和密碼進行驗證。除此之外,我想讓用戶有機會在Twitter上關注一些人。我創建了一個UIButton,現在想調用一個url或類似的東西來跟隨特定的用戶。這可能嗎?Twitter - 關注按鈕
回答
如果您使用的是iOS 6跟蹤用戶在Twitter上:
-(void)followMe
{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
[tempDict setValue:@"twitter_name" forKey:@"screen_name"];
[tempDict setValue:@"true" forKey:@"follow"];
NSLog(@"*******tempDict %@*******",tempDict);
//requestForServiceType
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/friendships/create.json"] parameters:tempDict];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i Error %d", [urlResponse statusCode],error.code];
NSLog(@"%@error %@", output,error.description);
}];
}
}
}];
}
非常好的答案,正是我正在尋找...謝謝! – RainCast 2016-10-25 04:51:44
簡單地做一個帖子
https://api.twitter.com/1.1/friendships/create.json
POST Data: user_id=1401881&follow=true
-(void)twitterButton
{
NSString *twitterAccount= @"yourAccountName";
NSArray *urls = [NSArray arrayWithObjects:
@"twitter://user?screen_name={handle}", // Twitter
@"tweetbot:///user_profile/{handle}", // TweetBot
@"echofon:///user_timeline?{handle}", // Echofon
@"twit:///user?screen_name={handle}", // Twittelator Pro
@"x-seesmic://twitter_profile?twitter_screen_name={handle}", // Seesmic
@"x-birdfeed://user?screen_name={handle}", // Birdfeed
@"tweetings:///user?screen_name={handle}", // Tweetings
@"simplytweet:?link=http://twitter.com/{handle}", // SimplyTweet
@"icebird://user?screen_name={handle}", // IceBird
@"fluttr://user/{handle}", // Fluttr
@"http://twitter.com/{handle}",
nil];
UIApplication *application = [UIApplication sharedApplication];
for (NSString *candidate in urls) {
NSURL *url = [NSURL URLWithString:[candidate stringByReplacingOccurrencesOfString:@"{handle}" withString:twitterAccount]];
if ([application canOpenURL:url])
{
UIWebView* Twitterweb =[[UIWebView alloc] initWithFrame:CGRectMake(.....)];
Twitterweb.delegate=nil;
Twitterweb.hidden=NO;
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[Twitterweb loadRequest:requestObj];
[self.view addSubview:Twitterweb];
return;
}
}
}
謝謝,但不是我正在尋找。我只是將數據發佈到上面的api url中。但是,無論如何,謝謝! – 2013-02-10 19:38:53
歡迎,很高興幫助 – Mutawe 2013-02-11 06:08:45
我跟着@Mohd阿西姆的回答執行下面的Swift代碼,謝謝你的回答。 :d
版本:iOS的10,夫特3
微博API:1.1
(https://dev.twitter.com/rest/reference/post/friendships/create)
class SocialHelper {
static func FollowAppTwitter() {
let accountStore = ACAccountStore()
let twitterType = accountStore.accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter)
accountStore.requestAccessToAccounts(with: twitterType, options: nil,
completion: { (isGranted, error) in
guard let userAccounts = accountStore.accounts(with: twitterType),
userAccounts.count > 0 else { return }
guard let firstActiveTwitterAccount = userAccounts[0] as? ACAccount else { return }
// post params
var params = [AnyHashable: Any]() //NSMutableDictionary()
params["screen_name"] = "pixelandme"
params["follow"] = "true"
// post request
guard let request = SLRequest(forServiceType: SLServiceTypeTwitter,
requestMethod: SLRequestMethod.POST,
url: URL(string: "https://api.twitter.com/1.1/friendships/create.json"),
parameters: params) else { return }
request.account = firstActiveTwitterAccount
// execute request
request.perform(handler: { (data, response, error) in
print(response?.statusCode)
print(error?.localizedDescription)
})
})
}
}
歡迎您)
- 1. 動態Twitter關注按鈕
- 2. SocialEngine4 - Twitter關注按鈕
- 3. 如何從Twitter中刪除「關注者」文本關注按鈕?
- 4. 「註冊Twitter」按鈕 - 如何
- 5. Rails:關注/關注關係按鈕
- 6. Google+關注按鈕
- 7. 關注/取消關注按鈕
- 8. Google +的回撥按鈕+關注按鈕
- 9. 隱藏關注Twitter的按鈕卡大段引用
- 10. Twitter關注按鈕作爲鏈接出現在Angular模板中
- 11. 爲什麼這個Twitter關注按鈕向下移動?
- 12. 如何在Android中集成Twitter關注按鈕?
- 13. 在Twitter上隱藏單詞「followers」關注按鈕
- 14. 如何更改Twitter關注按鈕寬度?
- 15. Twitter「關注」按鈕不會出現。只有文字
- 16. 官方Twitter關注按鈕代碼沒有通過驗證器
- 17. Twitter關注Url
- 18. Twitter關注API
- 19. Twitter Api關注
- 20. API-less linkedin關注按鈕
- 21. 關注按鈕問題
- 22. Twitter關注按鈕在Chrome 27及更低版本中未按預期工作
- 23. twitter關注者image24X24
- 24. 關注人Java Twitter
- 25. Twitter關注鏈接
- 26. JQueryUI模式關注關閉按鈕
- 27. 獲取Twitter關注者和關注ios7
- 28. 通過twitter在Twitter上關注關注者4j
- 29. 更換twitter按鈕
- 30. twitter登錄按鈕
看到的https: //github.com/chrismaddern/Follow-Me-On-Twitter-iOS-Button – 2013-02-10 11:44:49
或查看http ://stackoverflow.com/questions/10379201/how-to-add-twitter-follow-button-in-my-iphone-app – 2013-02-10 11:46:01