当我尝试获取访问令牌时,Instagram API提供“无效的平台应用程序”错误

问题描述 投票:0回答:1

我正在尝试使用以下API提取访问令牌:https://api.instagram.com/oauth/access_token。我已确保仅使用instagram应用程序ID,并且已将内容类型设置为“ x-www-form-urlencoded”,如以下答案所示:Authenticate the Test User { "error_type": "OAuthException", "code": 400, "error_message": "Invalid platform app" }。该API在邮递员中工作得很好,但是通过我的代码给出了以下错误响应:

{“ error_type”:“ OAuthException”,“ code”:400,“ error_message”:“无效的平台应用程序”}]

这是我的代码:

-(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是从前面步骤中收到的代码中删除#后的字符串。任何帮助表示赞赏。

objective-c swift instagram instagram-api
1个回答
0
投票

我在相同的情况下遇到相同的错误。

© www.soinside.com 2019 - 2024. All rights reserved.