如何从新的Instagram API获取访问令牌

时间:2020-03-04 23:50:12

标签: instagram instagram-api instagram-graph-api

Instagram已停止使用其旧的API,我正尝试在网站上显示另一个供稿。我无法通过Facebook上的测试人员帐户为开发人员创建新的访问令牌,但是此访问令牌的格式不同,因此无法在我的旧Feed上使用。

我的旧供稿正在使用https://api.instagram.com/v1

我这样称呼它:

var userFeed = new Instafeed({
                get: 'user',
                userId: '123123123',
                limit: 12,
                resolution: 'standard_resolution',
                accessToken: '123123123.testtest.d9128u12u312oijd0',
                sortBy: 'most-recent',
                template: '<div class="gallery instaimg"><a href="{{image}}" title="{{caption}}" target="_blank"><img src="{{image}}" alt="{{caption}}" class="img-fluid"/></a></div>',
            });

新的访问令牌更长,没有点。这是完全不同的格式。旧的看起来像这样 123123123.testtest.d9128u12u312oijd0

1 个答案:

答案 0 :(得分:0)

  https://api.instagram.com/oauth/authorize
  ?client_id={instagram-app-id}
  &redirect_uri={redirect-uri}
  &scope={scope}
  &response_type=code

将程序设置为https://developers.facebook.com/

后,您需要像这样使用

它将为您提供类似

的代码
RSATsRW.c3rwde...

之后,您发布

https://api.instagram.com/oauth/access_token \
  -F client_id=990602627938098 \
  -F client_secret=eb8c7... \
  -F grant_type=authorization_code \
  -F redirect_uri=https://socialsizzle.herokuapp.com/auth/ \
  -F code=RSATsRW.c3rwde...

它将为您提供令牌,用户名和ID

我从https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-access-tokens-and-permissions那里拿走了