Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram API responds with code 400 (Bad Request)

Tags:

api

instagram

I've sent this URL via post:

https://api.instagram.com/v1/users/XXX/relationship?action=unfollow&access_token=YYY

XXX is a valid userid, I've checked that multiple times. The token (YYY) is correct too.

This is the response:

{"meta":{"error_type":"APIInvalidParametersError","code":400,"error_message":"please supply action=approve,ignore,follow,block,unblock,unfollow"}}

I've tried action=follow and action=unfollow. Is it possible, that this is a bug? Where can I report it?

Instagram API Documentation: http://instagram.com/developer/endpoints/relationships/

like image 499
dislick Avatar asked Apr 16 '12 09:04

dislick


2 Answers

The problem is that you are not sending the action as postdata. I had the exact problem just yesterday.

The access_token should be sent in the url, but the action=follow should be in the postdata of the request!

like image 193
zolipapa Avatar answered Oct 01 '22 09:10

zolipapa


NSString *initialURL = [NSString stringWithFormat:@"https://api.instagram.com/v1/users/USER_ID/relationship?access_token=ACCESS TOKEN"];
NSURL *url=[NSURL URLWithString:initialURL];

NSString *key = [NSString stringWithFormat:@"action=follow"];
NSData *mastData = [key dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *mastLength = [NSString stringWithFormat:@"%d",[mastData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:mastLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:mastData];
NSURLConnection *con=[[NSURLConnection alloc]initWithRequest:request delegate:self];
[con start];
like image 28
Gurpreet Singh Avatar answered Oct 01 '22 10:10

Gurpreet Singh