【发布时间】:2012-09-30 23:01:21
【问题描述】:
我想通过单击按钮来关注 Twitter 用户。我使用了使用 oauth 的 share kit follow me 方法。但我总是收到此错误。
{"error":"无法通过身份验证 OAuth.","request":"/1/friendships/create/priyankav89.json"}
然后我尝试自己实现它
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/friendships/create.json"];
NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
[dict setObject:@"871252998" forKey:@"user_id"];
[dict setObject:@"true" forKey:@"follow"];
[dict setObject:@"KXL0jFLJY6RI4lszOz8r5w" forKey:@"consumer"];
NSString *jsonRepresentation=[dict JSONString];
NSLog(@"jsonRepresentation = %@",jsonRepresentation);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:3];
NSData *postData=[NSData dataWithBytes:jsonRepresentation.UTF8String length:[jsonRepresentation length]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *error=nil;
NSData *responseData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"respon = %s",responseData.bytes);
我仍然遇到同样的错误。
我搜索了很多。还是没用。我不想在 UIWebView 或 safari 中加载 url。我想支持来自 ios4 的应用程序。所以无法使用ios5内置的推特应用。
【问题讨论】:
-
你有没有使用sharekit?
-
我尝试了 twitter 的分享工具包跟随我的方法。但它不起作用。我正在使用共享工具包来共享运行良好的文本。
-
简而言之,你想在 Twitter 上分享什么?
-
检查是否先通过身份验证?另外,检查 Oauth 是否可行。
标签: iphone ipad twitter sharekit twitter-follow