Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c Instagram API提供;无效的平台应用程序“;尝试获取访问令牌时出错_Objective C_Swift_Instagram_Instagram Api - Fatal编程技术网

Objective c Instagram API提供;无效的平台应用程序“;尝试获取访问令牌时出错

Objective c Instagram API提供;无效的平台应用程序“;尝试获取访问令牌时出错,objective-c,swift,instagram,instagram-api,Objective C,Swift,Instagram,Instagram Api,我正在尝试使用以下API获取访问令牌:。我已确保仅使用instagram应用程序ID,并按照以下答案中的建议,将内容类型设置为“x-www-form-urlencoded”:。虽然API在postman中工作得非常好,但通过我的代码给出了以下错误响应: {“错误类型”:“OAutheException”,“代码”:400,“错误消息”:“无效平台应用程序”} 以下是我的代码: -(void)fetchAccessTokenForInsta{ NSString *targetUrl = [NSS

我正在尝试使用以下API获取访问令牌:。我已确保仅使用instagram应用程序ID,并按照以下答案中的建议,将内容类型设置为“x-www-form-urlencoded”:。虽然API在postman中工作得非常好,但通过我的代码给出了以下错误响应:

{“错误类型”:“OAutheException”,“代码”:400,“错误消息”:“无效平台应用程序”}

以下是我的代码:

-(void)fetchAccessTokenForInsta{

NSString *targetUrl = [NSString stringWithFormat:@"%@", @"https://api.instagram.com/oauth/access_token"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

NSDictionary *tmp = @{@"client_id":@"126.....", @"client_secret":@"c79c.....", @"grant_type":@"authorization_code", @"redirect_uri":@"https://firebase.google.com/", @"code":_codeStr};
NSError *error;
NSData *postData = [NSJSONSerialization dataWithJSONObject:tmp options:0 error:&error];

[request setHTTPBody:postData];
[request setHTTPMethod:@"POST"];
[request setURL:[NSURL URLWithString:targetUrl]];

NSDictionary *headers = @{@"Content-Type": @"application/x-www-form-urlencoded" };
[request setAllHTTPHeaderFields:headers];

[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:
  ^(NSData * _Nullable data,
    NSURLResponse * _Nullable response,
    NSError * _Nullable error) {

      NSString *responseStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
      NSLog(@"Data received: %@", responseStr);
}] resume];
}

其中_codeStr是从前面步骤中接收到的代码中删除#后的字符串。非常感谢您的帮助。

到目前为止,唯一有效的解决方案是让您的服务器或后端团队为您开发一个API,使用instagram API获取访问令牌并将其作为响应提供给您。

我也有同样的问题。我以错误的方式发送参数。在我的例子中,我省略了querystring.stringify数据对象,在这里我有所有的参数。