【问题标题】:Instagram - How to follow the user using API in Objective CInstagram - 如何在 Objective C 中使用 API 关注用户
【发布时间】:2014-04-09 05:57:40
【问题描述】:

我会在我的应用程序的帮助下关注任何用户。有人可以建议我该怎么做吗?当我从here 阅读 Instagram API 时。但没有得到正确的想法该做什么。

【问题讨论】:

  • 嘿 Lithu,这意味着我必须将 /relationship 与“follow/unfollow/block/unblock/approve/deny”选项之一一起使用,对吧?
  • 哦,谢谢您的快速回复,将尽快检查并更新您:)
  • 谁能提供一些样品?正如我在这里尝试过的,但没有得到任何运气。
  • @Nirmit 如果您尝试过。在此处发布您的代码,这将有助于解决您的问题

标签: ios objective-c instagram


【解决方案1】:

你可以这样做:-

NSString *urlString=[NSString stringWithFormat:@"https://api.instagram.com/v1/users/%@/relationship?access_token=%@",<user id>,<access token>];

    NSURL* url = [NSURL URLWithString:urlString];
    theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:1000.0];
    NSString *parameters=@"action=follow";
    [theRequest setHTTPBody:[parameters dataUsingEncoding:NSUTF8StringEncoding]];
    [theRequest setHTTPMethod:@"POST"];

【讨论】:

    【解决方案2】:

    要关注我们只需要client_id

    首先通过注册your app on Instagram创建一个client_id

    并在 webView 中打开给定的 Url。

            NSString *urlAddress =[NSString stringWithFormat:@"https://instagram.com/oauth/authorize/?client_id=%@&redirect_uri=http://appbellfitness.com/&response_type=token&scope=likes+comments+relationships",client_id];
    
            NSURL *nsurl=[NSURL URLWithString:urlAddress];
    
            NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
    
            [webview loadRequest:nsrequest];
    
            webview.delegate = self;
    

    并向其添加 WebView 委托。

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    {
        NSString *orignalUrl =[request.URL absoluteString];
    
        if ([orignalUrl hasPrefix:CALLBACKURL])
        {
            NSArray* parts = [orignalUrl componentsSeparatedByString: @"="];
    
            request_token = [parts objectAtIndex: 1];
    
            NSString *myurl =[NSString stringWithFormat:@"https://api.instagram.com/v1/users/25025320/relationship?access_token=%@",request_token];
    
            NSString *action=@"action=follow";
    
            BsyncTask *task = [[BsyncTask alloc]init];
    
            [task asynchronousPost:action url:myurl callerName:@"followTask"];//post this as you like
    
            task.recieveAsyncResponse = self;
        }
    
        return YES;
    }
    

    应该StartLoadWithRequest 我检查它从我的重定向 Uri 开始,然后通过在 = 符号的基础上分隔 url 来获取访问令牌。然后我使用我的班级发布它,您可以随意发布它并获得响应。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多