我正在开发 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];
}