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.
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"];
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With