如何收集Instagram应用程序Secret来产生长期的令牌?

发布于 2025-02-07 22:55:15 字数 2428 浏览 3 评论 0原文

on 此页面我生成了访问令牌,然后我可以在Instagram上发布图像:

出版:

function InstagramPost() {
  const access_token = 'GENERATE ACESS TOKEN';
  const instagram_business_account = 'YYYYYYYYYYYYYYYYYY';
  
  const image = 'https://upload.wikimedia.org/wikipedia/en/9/95/Test_image.jpg';
  const text = 'Hello World';
  var formData = {
    'image_url': image,
    'caption': text,
    'access_token': access_token
  };
  var options = {
    'method' : 'post',
    'payload' : formData
  };
  const container = 'https://graph.facebook.com/v14.0/' + instagram_business_account + '/media';

  const response = UrlFetchApp.fetch(container, options);

  const creation = response.getContentText();
  var data = JSON.parse(creation);
  var creationId = data.id
  var formDataPublish = {
      'creation_id': creationId,
      'access_token': access_token
  };
  var optionsPublish = {
    'method' : 'post',
    'payload' : formDataPublish
  };
  const sendinstagram = 'https://graph.facebook.com/v14.0/' + instagram_business_account + '/media_publish';
  
  UrlFetchApp.fetch(sendinstagram, optionsPublish);
}

现在我想取下此访问令牌并生成长寿与之相关!

它要求 Instagram应用秘密,但是该路径指示(App dashboard&gt; products&gt; instagram&gat; basic display&gt; instagram app secret)在< em>应用仪表板!

我尝试使用 app secret 作为参数:

“在此处输入图像说明”

"https://graph.instagram.com/access_token
  ?grant_type=ig_exchange_token
  &client_secret={App Secret Key}
  &access_token={short-lived-access-token}"

但是发生此错误:

Sorry, this content isn't available right now

Facebook API 100%可访问,所以这不是问题。

On this page I generate the access token and with it I can publish the image on my Instagram:

enter image description here

For publish:

function InstagramPost() {
  const access_token = 'GENERATE ACESS TOKEN';
  const instagram_business_account = 'YYYYYYYYYYYYYYYYYY';
  
  const image = 'https://upload.wikimedia.org/wikipedia/en/9/95/Test_image.jpg';
  const text = 'Hello World';
  var formData = {
    'image_url': image,
    'caption': text,
    'access_token': access_token
  };
  var options = {
    'method' : 'post',
    'payload' : formData
  };
  const container = 'https://graph.facebook.com/v14.0/' + instagram_business_account + '/media';

  const response = UrlFetchApp.fetch(container, options);

  const creation = response.getContentText();
  var data = JSON.parse(creation);
  var creationId = data.id
  var formDataPublish = {
      'creation_id': creationId,
      'access_token': access_token
  };
  var optionsPublish = {
    'method' : 'post',
    'payload' : formDataPublish
  };
  const sendinstagram = 'https://graph.facebook.com/v14.0/' + instagram_business_account + '/media_publish';
  
  UrlFetchApp.fetch(sendinstagram, optionsPublish);
}

Now I want to take this access token and generate a long-lived one with it!

It asks for Instagram App Secret, but that path indicated (App Dashboard > Products > Instagram > Basic Display > Instagram App Secret) doesn't exist in App Dashboard!

enter image description here

I tried using the App secret as a parameter:

enter image description here

"https://graph.instagram.com/access_token
  ?grant_type=ig_exchange_token
  &client_secret={App Secret Key}
  &access_token={short-lived-access-token}"

But this error occurs:

Sorry, this content isn't available right now

The Facebook API is 100% accessible, so that's not the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一江春梦 2025-02-14 22:55:15

在JavaScript/nodejs中,我根本无法使用它(也在Postman上),我正在使用request库。

将我的代码更改为:

const respLong = await axios.get(`https://graph.instagram.com/access_token?grant_type=ig_exchange_token&client_secret=${CLIENT_SECRET}&access_token=${accessTokenShort.toString()}`);

神奇地工作。我无法告诉您为什么Postman中似乎完全相同的请求,而请求库不起作用。

请参阅URL的图片,以获取应用程序秘密(添加您的应用ID)是: https://developers.facebook.com/apps/your_app_id(number)/instagram-basic-display/basic-display/
在这里说明“

In Javascript/NodeJS I couldn't get it working at all (also on PostMan), I was using the request library.

Changed my code to:

const respLong = await axios.get(`https://graph.instagram.com/access_token?grant_type=ig_exchange_token&client_secret=${CLIENT_SECRET}&access_token=${accessTokenShort.toString()}`);

And magically this works. I can't tell you why what seems to be the exact same request in Postman and the request library doesn't work.

See pic of the url to get app secret (add your app ID) is: https://developers.facebook.com/apps/YOUR_APP_ID(number)/instagram-basic-display/basic-display/
enter image description here

半城柳色半声笛 2025-02-14 22:55:15

基本显示 Instagram图API 之间的方法有所不同。

因此,将短暂令牌转换为Instagram业务帐户的长寿令牌的方法是:

"https://graph.facebook.com/{graph-api-version}/oauth/access_token?  
    grant_type=fb_exchange_token&          
    client_id={app-id}&
    client_secret={app-secret}&
    fb_exchange_token={your-short-lived-access-token}"

请注意,Instagram App Secret不使用,而是使用App app iDApp Secret

There is a difference in approach between Basic Display and Instagram Graph API for Business Account.

So the way to convert a short-lived token to a long-lived token for Instagram Business Account is:

"https://graph.facebook.com/{graph-api-version}/oauth/access_token?  
    grant_type=fb_exchange_token&          
    client_id={app-id}&
    client_secret={app-secret}&
    fb_exchange_token={your-short-lived-access-token}"

Note that Instagram App Secret is not used, instead, use App Id and App Secret.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文