Twitter关注API

时间:2014-01-07 06:32:47

标签: twitter

我需要让这个人使用API​​在Twitter上关注另一个人。

我知道twitter已迁移到v1.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可以找到我的解决方案。

任何人都帮我找到一个人跟随另一个人。

2 个答案:

答案 0 :(得分: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

                }
            }];
        }
    }
}];
}

答案 1 :(得分:0)

你可以查看这个答案: 在v1.1 API中,他们已使用friendships / lookup API替换它,您可以在其中指定最多100个用户的逗号分隔列表,它将告诉您身份验证用户与指定的每个用户之间的连接< / p>