Instagram - 如何在Objective C中使用API​​跟踪用户

时间:2014-04-09 05:57:41

标签: ios objective-c instagram

我希望在我的应用程序的帮助下关注任何用户。谁能建议我做什么?当我从here阅读 Instagram API 时。但没有正确的想法做什么。

2 个答案:

答案 0 :(得分:6)

你可以这样做: -

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"];

答案 1 :(得分:1)

要关注,我们只需要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;
}

<强> shouldStartLoadWithRequest  我检查它是从我的重定向Uri开始然后我通过基于=符号分隔URL来获取访问令牌。然后我使用我的课程发布它你可以随意发布并获得回复。