在 android 中集成 Instagram 身份验证
Integrating instagram authentication in android
我正在构建一个使用 instagram API 的 android 应用程序,我想知道是否有一种解决方案可以避免构建 api(重定向 uri)来处理来自 instragram 身份验证端点的重定向用于 android 客户端的令牌检索。
我想你可以用他们的 Client side (implicit) authentication 做到。查看文末部分。
Once the user has authenticated and then authorized your application,
Instagram redirects them to your redirect_uri with the access_token in
the url fragment. It will look like this:
http://your-redirect-uri#access_token=ACCESS-TOKEN
Simply grab the
access_token off the URL fragment and you’re good to go. If the user
chooses not to authorize your application, you’ll receive the same
error response as in the explicit flow.
关键部分是您必须定义重定向 uri,但在这种情况下它必须无效。例如,如果您使用 www.google.com
作为重定向 uri,身份验证后用户将被重定向到
此时,您必须不能让用户前进。相反,捕获重定向并解析 URI 字符串,以便您可以获得访问令牌。
如果您的导航发生在 WebView 内部,这可能会发生在 shouldOverrideUrlLoading()
回调中(来自 WebViewClient):
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http://www.google.com") { // redirect uri!
String accessToken = ... // get token from url
return true; // don’t load the page
}
return false;
}
这会有些痛苦,例如错误处理,但是嘿,如果他们有客户端身份验证,它应该也适合你。
我正在构建一个使用 instagram API 的 android 应用程序,我想知道是否有一种解决方案可以避免构建 api(重定向 uri)来处理来自 instragram 身份验证端点的重定向用于 android 客户端的令牌检索。
我想你可以用他们的 Client side (implicit) authentication 做到。查看文末部分。
Once the user has authenticated and then authorized your application, Instagram redirects them to your redirect_uri with the access_token in the url fragment. It will look like this:
http://your-redirect-uri#access_token=ACCESS-TOKEN
Simply grab the access_token off the URL fragment and you’re good to go. If the user chooses not to authorize your application, you’ll receive the same error response as in the explicit flow.
关键部分是您必须定义重定向 uri,但在这种情况下它必须无效。例如,如果您使用 www.google.com
作为重定向 uri,身份验证后用户将被重定向到
此时,您必须不能让用户前进。相反,捕获重定向并解析 URI 字符串,以便您可以获得访问令牌。
如果您的导航发生在 WebView 内部,这可能会发生在 shouldOverrideUrlLoading()
回调中(来自 WebViewClient):
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http://www.google.com") { // redirect uri!
String accessToken = ... // get token from url
return true; // don’t load the page
}
return false;
}
这会有些痛苦,例如错误处理,但是嘿,如果他们有客户端身份验证,它应该也适合你。