【问题标题】:iPhone follow a user on twitter programmaticallyiPhone 以编程方式在 Twitter 上关注用户
【发布时间】:2012-09-30 23:01:21
【问题描述】:

我想通过单击按钮来关注 Twitter 用户。我使用了使用 oauth 的 share kit follow me 方法。但我总是收到此错误。

{"error":"无法通过身份验证 OAuth.","re​​quest":"/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


【解决方案1】:

我发现了问题。在 share kit follow me 方法中,他们在关注之前没有调用授权方法。所以我们想在登录前调用授权并保存访问令牌。

【讨论】:

    【解决方案2】:

    假设你知道如何使用集成到 iOS 的 twitter 发推文,你可以简单地发推文“关注”

    【讨论】:

      猜你喜欢
      • 2012-01-27
      • 2011-09-14
      • 1970-01-01
      • 2012-06-15
      • 2013-07-30
      • 2014-11-17
      • 1970-01-01
      • 2012-07-20
      • 1970-01-01
      相关资源
      最近更新 更多