问题描述
我有一个应用程序,可以从我的Instagram帐户中提取数据.我曾经授权过此应用一次,并获得了访问令牌.但是我很担心如果该令牌过期怎么办?我是否应该每次都授权该应用令牌到期?我可以从验证码中收到另一个访问令牌吗?如果没有,我该怎么做才能让我的应用始终从帐户中提取数据没有我的参与?谢谢.
I have an app, that pulls data from my Instagram account.I authorized this app once, and got access token. But I'm worried,what if this token expires? Should I authorized the app each time thetoken expires?Can I receive another access token from the auth code?If no, what can I do to have my app always pulling data from accountwithout my participation?Thanks.
推荐答案
AFAIK,Instagram访问令牌目前尚未过期.
AFAIK, Instagram accesstokens don't expire currently.
注意::来自Instagram文档.
请注意,我们不包括到期时间.我们的access_tokens没有明确的到期时间,尽管您的应用应处理以下情况:用户撤销访问权限,或者我们在一段时间后使令牌过期.在这种情况下,您的响应的元数据将包含"error_type = OAuthAccessTokenError".换句话说:不要假设您的access_token永远有效.
Note that we do not include an expiry time. Our access_tokens have no explicit expiry, though your app should handle the case that either the user revokes access or we expire the token after some period of time. In this case, your response’s meta will contain an "error_type=OAuthAccessTokenError". In other words: do do not assume your access_token is valid forever.
目前,您不需要这样做,因为令牌不会过期.随着令牌在将来失效,将会向您发送相应的警告或错误代码和消息,您需要进行处理.
At the moment, you do not need to do that, as token does not expire. As and when the token expires in future, a corresponding warning or error code and message will be sent to you, which you need to handle.
您可以尝试以下操作:
-
使用sharedpreference存储访问令牌.
Use sharedpreference to store the accesstoken.
首次尝试获取需要访问令牌(经过身份验证的请求)的数据时,请首先在sharedpreference中检查是否存储了访问令牌.如果是,那么您无需登录,只需使用该访问令牌.如果您没有偏好的访问令牌,请使用instagram凭据登录,获取访问令牌,然后以共享的偏好共享它,并将其用于后续请求.
First time when you try to fetch data that needs accesstoken(Authenticated requests), first check in the sharedpreference whether the accesstoken is stored or not.if yes then you don't need to login, just use that accesstoken. If you don't have the accesstoken in preference then do the login using instagram credentials, get the accesstoken and then share it in shared preference and use that for subsequent requests.
您可以提供instagram注销选项,您只需要从sharedprefernce中清除访问令牌即可.
You can provide instagram logout option in which you just need to clear the accesstoken from sharedprefernce.
希望这对您有帮助.
这篇关于Instagram访问令牌过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!