Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram - How to follow the user using API in Objective C

I would to follow any user with the help of my application. Can anybody suggest me what to do ? As I read the Instagram API from here. But not getting proper idea what to do.

like image 401
Nirmalsinh Rathod Avatar asked Mar 20 '23 22:03

Nirmalsinh Rathod


2 Answers

You can do this way :-

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"];
like image 143
Sivakumar Punniyakotti Avatar answered Mar 22 '23 11:03

Sivakumar Punniyakotti


To follow we only need client_id

First of all create a client_id by registering your app on Instagram

and open given Url in webView.

        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;

And add WebView delegate to it.

- (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 I check it starts with my redirect Uri then I get the access token by seperating the url on the basis of = sign. and then i post it using my class you can post it as you like and get response.

like image 21
Zar E Ahmer Avatar answered Mar 22 '23 12:03

Zar E Ahmer