验证测试用户{“ error_type”:“ OAuthException”,“ code”:400,“ error_message”:“无效的平台应用”}


Answers:


26

菲利斯!

设置Instagram应用程序时,您应该使用平台特定的应用程序ID,而不要使用Facebook上的通用设置。

在您的Facebook应用程序仪表板中,转到Products > Instagram > Basic Display并应看到Instagram应用程序ID

在您的授权URL中使用它,它应该可以工作。


您是否找到了解决方案?我有同样的问题。
MontyTheMack

4
我正在使用Instagram应用程序ID,但仍然出现此错误。
MontyTheMack

1
同样在这里。我注意到无论您在[ api.instagram.com/oauth/access_token/]加上什么参数,都会抛出错误!也许是一个糟糕的终点?无论如何,我都会按照[ developers.facebook.com/docs/instagram-basic-display-api/…上提到的所有步骤进行逐步操作,并且一切工作都很好,直到步骤5:将代码交换为令牌,然后再使用邮递员使用参数client_id,client_secret,grant_type,redirect_uri和代码(成功获得授权后调用)调用[ api.instagram.com/oauth/access_token/]。但失败了
DingDong

6
我遇到了同样的问题,我用邮递员进行了测试,将参数传递给身体并设置了x-www-form-urlencoded,它的工作原理像cham
Michael de Menten


2

我遇到了类似的问题,并且能够通过将请求的内容类型设置为application / x-www-form-urlencoded来解决此问题。以下是显示如何执行请求的ac#示例:

public async Task<UserTokenResponseModel> GetUserToken(string code)
    {
        var url =
            $"https://api.instagram.com/oauth/access_token";

        var request = new HttpRequestMessage(HttpMethod.Post, url);

        var client = _httpClientFactory.CreateClient();

        var requestContent = new List<KeyValuePair<string, string>>();
        requestContent.Add(new KeyValuePair<string, string>("client_id", ClientId));
        requestContent.Add(new KeyValuePair<string, string>("client_secret", Secret));
        requestContent.Add(new KeyValuePair<string, string>("grant_type", "authorization_code"));
        requestContent.Add(new KeyValuePair<string, string>("code", code));
        requestContent.Add(new KeyValuePair<string, string>("redirect_uri", "https://localhost:44315/instagram/authorizecallback"));

        request.Content = new FormUrlEncodedContent(requestContent);

        var response = await client.SendAsync(request);
        var content = await response.Content.ReadAsStringAsync();

        if (!response.IsSuccessStatusCode)
        {
            throw new Exception(content);
        }

        return JsonConvert.DeserializeObject<UserTokenResponseModel>(content);
    }

1

就像在其他答案中提到的那样,问题在于应该以x-www-form-urlencoded格式发送的表单主体。对于邮递员来说,这对我来说还算不错,但是在角度上实现同样的效果有点典型。在这里,发布请求主体必须首先转换为HttpParams格式,然后像这样将字符串传递给发布请求的'body'参数。

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class appService {

  constructor(private http: HttpClient) { }

  public getInstaAccessToken(formData) {
    let full_url = "https://api.instagram.com/oauth/access_token";
    let body = new HttpParams()
      .set("client_id" , "YOUR_CLIENT_ID")
      .set("client_secret","YOUR_CLIENT_SECRET")
      .set("code","code received from redirect url")
      .set("grant_type","authorization_code")
      .set("redirect_uri","your redirect uri")
    const requestOptions = {
      headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
    }
    return this.http.post(full_url, body.toString(), requestOptions).subscribe(data=>{
      console.log(data);
      /* 
        {
          "access_token": "IGQVJ...",
          "user_id": 17841405793187218
        }
      */
    })
  }

}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.