获取Instagram访问令牌 [英] Obtaining Instagram Access Token

查看:184
本文介绍了获取Instagram访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个客户,该客户在网站上具有简单的Instagram功能,可以按特定标签提取照片.他们只是注意到它不起作用.收到错误-无效的访问令牌.我猜因为第一天是因为更新.我们以前不需要访问令牌,因为我们不对用户做任何事情-只是标签.

We have a client who has a simple Instagram feature on the site to pull photos by a certain tag. They just noticed it isn't working. Getting an error - invalid access token. I guess since the 1st because of the updates. We didn't used to need an access token since we're not doing anything with users - just tags.

现在看来,我们需要一个,而文档中关于获取一个的意义为零.看来他们不接受大多数应用程序.该应用程序也处于沙盒模式.所以我假设这是因为它被切换到了那个?对此事没有任何通知.

Now it looks like we need one and the documentation makes zero sense on how to obtain one. And it seems like they're not accepting most apps. The app is in sandbox mode too. So I'm assuming it's because it got switched to that? Got no notification of this happening.

获取访问令牌的文档的第一步是将用户定向到我们的授权URL".那有什么意思?没有提供链接或其他任何内容.它还说:开始提交需要公司名称,联系电子邮件和隐私政策URL."我们的应用没有隐私政策,只是一个简单的标签供稿.我不明白为什么要使用简单的标签供稿,一切都会如此复杂.

The first step in documentation to get an access token is "Direct the user to our authorization url." What does that even mean? There's not a link provided or anything. It also says "Company Name, Contact Email and Privacy Policy URL are required to start a submission." Our app doesn't have a privacy policy... it's just a simple tag feed. I don't understand why everything is so complex to have a simple tag feed.

是否有等待时间才能批准该应用..如果获得批准...我是否需要在获得访问令牌之前批准它?在任何地方都没有概述.

Is there a wait time to get the app approved..if it gets approved... Do I have to have it approved before getting an access token? This isn't outlined anywhere.

推荐答案

您说对了.从2016年6月开始,任何Instagram API调用都需要访问令牌.

You got it right. As of June 2016 any Instagram API calls require an access token.

文档中介绍了获取访问令牌的方法.无需应用批准.

Getting an access token is described in the documentation. App approval is not required.

有两种获取方法:服务器端或客户端.仅当在客户端设置(管理客户端>编辑客户端>安全>禁用隐式OAuth )中启用了隐式OAuth 时,才可以使用第二个选项(称为隐式身份验证).默认情况下它是禁用的.

There are two ways to get one: server-side or client-side. The second option (called implicit authentication) can only be used when implicit OAuth is enabled in the client settings (Manage Clients > Edit Client > Security > Disable implicit OAuth). It is disabled by default.

无论哪种情况,您都需要将用户重定向到授权URL以获得访问令牌.

In either case you need to redirect the user to the authorization URL to obtain an access token.

显式模式(服务器端)的URL是:

The URL for explicit mode (server side) is:

https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code

隐式模式(客户端)的URL为:

The URL for implicit mode (client side) is:

https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token

此后,您将被重定向到REDIRECT-URI,它将被传递一个参数.对于显式模式,这将是带有 code 的查询字符串,而对于隐式模式,您将直接获得作为散列的访问令牌:

After this you will be redirected to the REDIRECT-URI, which will be passed an argument. For explicit mode this will be a query string with a code, while for implicit mode you will get the access token directly as a hash:

http://your-redirect-uri?code=CODE
http://your-redirect-uri#access_token=ACCESS-TOKEN

对于隐式模式,您可以从Java脚本中的window.location.hash获取访问令牌.

For implicit mode you can then get the access token from the window.location.hash in Javascript.

但是,对于显式模式,您需要进一步处理 code 以获得访问令牌.您可以在 API文档中了解如何完成此操作.我在这里不做进一步介绍.

For explicit mode, however, you need to further process the code to obtain the access token. You can read how this can be done in the API Documentation. I'm not going to take this any further here.

问题在于,要查看您的供稿的每个用户需要登录Instagram(并拥有一个帐户)才能查看它.在您的情况下,这可能是不希望的.但是,有一些方法可以解决此(相当烦人的)问题:

The problem is that every user who wants to see your feed needs to login to Instagram (and have an account) in order to view it. In your case this might not be desired. However, there are a few options to get around this (rather annoying) problem:

  1. 您可以重复使用自己的(已获取)访问令牌来为每个用户显示Instagram供稿.您将需要了解每个令牌的速率限制.对于沙盒应用程序,这是每小时500个API调用,而实时模式允许每小时5000个API调用. [源] 您可以将令牌存储在表中并使用它们以循环方式进行,以允许更多的API调用.这涉及手动获取一堆可以供您的应用程序使用的令牌(越多越好).考虑到Instagram不保证访问令牌的生命周期不受限制,这可能不是理想的解决方案.

  1. You can reuse your own (already obtained) access token(s) to display the Instagram feed for every user. You will need to be aware of rate limits for each token. For sandboxed apps this is 500 API calls / hour, while live mode allows 5000 API calls / hour. [source] You could store tokens in a table and use them in a round-robin manner, to allow more API calls. This involves manually obtaining a bunch of tokens which your application can use (the more the better). This might not be the ideal solution considering Instagram doesn't warrant access tokens to have an unlimited lifetime.

这篇文章中所述,您可以通过将/media/附加到用户页面URL来检索JSON数据而无需身份验证. /a>.无需令牌或客户端ID即可运行.但是,这仅适用于用户,不适用于标签.此外,Instagram并未记录此功能,因此不保证将来可以使用.

You can retreive JSON data without authentication by appending /media/ to a user page URL, as described in this post. No tokens or client IDs are required for this to work. However, this only works for users, not for tags. Besides, Instagram doesn't document this feature so it is not garanteed to work in the future.

您可以使用榨汁机

You can use an aggregator like Juicer or Dialogfeed instead which will handle access tokens for you. This is usually not free of charge.

我也正在为我的网站制作Instagram提要,这就是我从研究中得出的结论.请说明我犯的任何错误.

I'm also in the process of making an Instagram feed for my website, and this is what I concluded from my research. Please bare with any errors I made.

编辑:这是沙箱应用的更多限制.

Here are some more limitations for sandbox apps.

在沙盒模式下,您只能访问沙盒用户(因此收到沙盒邀请的用户)的数据.这意味着:

In sandbox mode you can only access data from sandbox users (thus users who received a sandbox invite). This means that:

  • 用户获取的媒体,例如/users/{user-id}/media/recent,如果该用户不是沙盒用户,则将返回空响应.
  • 通过标签检索的媒体,例如/tags/{tag-name}/media/recent,将仅包含属于沙箱用户的标记媒体.
  • Media retreived by user, e.g. /users/{user-id}/media/recent, will return an empty response if the user is not any of the sandbox users.
  • Media retreived by tag, e.g. /tags/{tag-name}/media/recent, will only contain tagged media belonging to sandbox users.

因此,要使标签供稿正常工作,需要 处于活动状态(已审核并获得批准).如果您不想这样做,那么唯一的选择就是使用如上所述的聚合器.

Thus, for a tag feed to work, it needs to be live (reviewed and approved). If you don't want to do this, the only alternative is to use an aggregator as I mentioned above.

这篇关于获取Instagram访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆