我正在开发iOS应用程序,用户可以从Twitter登录并关注某些用户。但是关注不起作用。
- (void)executeFollowRequestWithComplition:(nonnull SuccessResultBlock)complition {
NSURLSessionConfiguration *defaultSessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration:defaultSessionConfiguration];
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/friendships/create.json"];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
NSString *postParams = [NSString stringWithFormat:@"screen_name=%@&follow=true", twitterName];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[postParams dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
ANSPerformBlock(complition, (error == nil), error)
}];
[dataTask resume];
}
答案 0 :(得分:0)
您的请求中似乎没有任何身份验证信息。
如果您查看twitter文档,它将为您提供一个curl示例
LOGGED_IN = NOT_LOGGED_OUT && LAST_VISIT > time() - 15*60 # 15 minutes
您缺少的重要信息在这里
UPDATE user_table SET last_visit = UNIX_TIMESTAMP() WHERE user_id=?
您可以通过添加每个标头字段来附加该信息
SELECT COUNT(*) from user_table
WHERE !logged_out && last_visit > UNIX_TIMESTAMP() - 15*60