Instagram - How to Follow a User Using an API in Objective-C

I would like to follow any user using my application. Can someone suggest me what to do? When I read the Instagram API from here . But do not get the right idea of ​​what to do.

+4
source share
2 answers

You can do this: -

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"];
+6
source

To follow, we only need client_id

First, create client_id by registering your application on Instagram

and open this 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 a 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   , Uri, , URL =. , , , .

+1

Source: https://habr.com/ru/post/1535683/


All Articles