2014-01-07 71 views
0

我需要讓這個人在Twitter上使用API​​來關注另一個人。Twitter關注API

我知道嘰嘰喳喳遷移到1.1版

我使用這些API來得到兩個人之間的關係,

https://api.twitter.com/1.1/friendships/exists.json?screen_name_a=Person1&screen_name_b=Person2

https://api.twitter.com/1.1/friendships/lookup.json?screen_name=Person1,Person2

,但我得到的最終結果是,

{ 
errors =  (
      { 
     code = 215; 
     message = "Bad Authentication data"; 
    } 
); 
} 

是否有任何其他確切的API可以找到我的解決方案。

任何人都可以幫助我找到一個人跟隨另一個人。

+0

的錯誤是「壞的認證數據」 - 你有沒有正確註冊你的應用程序,並得到您的認證令牌? –

+0

特倫斯伊登謝謝你的回覆。我用這個方法http://stackoverflow.com/questions/8085055/how-to-follow-people-with-the-new-twitter-api-in-ios-5,它工作正常。 –

回答

1

試試這個代碼,你可以得到你所期待的東西,

-(void) followUsOnTwitter { 

ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 

ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(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:@"abcd" forKey:@"screen_name"]; // Change the Value String 
      [tempDict setValue:@"true" forKey:@"follow"]; 

      TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/friendships/create.json"] 
                 parameters:tempDict 
                 requestMethod:TWRequestMethodPOST]; 

      [postRequest setAccount:twitterAccount]; 

      [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
       NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]]; 
       NSLog(@"%@", output); 
       if (urlResponse.statusCode == 200) 
       { 

        // follow by usr 

       } 
      }]; 
     } 
    } 
}]; 
} 
0

你可以檢查這個答案: 在v1.1 API中,他們用友誼/查找API代替它,你可以指定一個逗號分隔的列表,最多可以有100個用戶,它會告訴你關於認證用戶和每個用戶之間的連接指定

+0

Anil Dhiman,我也檢查過它,只是看到我的問題在第二個鏈接,.. –