我正在使用Instagram API而且我不明白我应该为重定向api做些什么。目前我只需输入https://127.0.0.1
但我真的不明白。此外,一旦我得到允许/取消屏幕,我按下允许它给我一个错误,说我不能去那个地址,但我也可以看到附加在地址上的授权码。那么我如何从我的重定向uri重定向回来?如何告诉android用户点击后允许返回应用程序使用代码进行进一步的身份验证?
我相信你会说一些像制作我自己的自定义方案/意图过滤器等的东西,但请多一点支持我新的,我不明白,我确实研究过它们。
我的简历方法在
之下@Override
protected void onResume() {
super.onResume();
// the intent filter defined in AndroidManifest will handle the return from ACTION_VIEW intent
Uri uri = getIntent().getData();
if (uri != null && uri.toString().startsWith(redirectUri)) {
// use the parameter your API exposes for the code (mostly it's "code")
String code = uri.getQueryParameter("code");
if (code != null) {
// get access token
LoginService loginService =
ServiceGenerator.createService(LoginService.class, clientId, clientSecret);
AccessToken accessToken = loginService.getAccessToken(code, "authorization_code");
} else if (uri.getQueryParameter("error") != null) {
// show an error message here
}
}
}
这是我处理意图过滤器的清单摘录:
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="redirecturi"
android:scheme="your" />
</intent-filter>
</activity>
答案 0 :(得分:2)
您必须在浏览器视图中设置事件侦听器,如果URL等于redirect_uri,则检查URL参数中的code
,然后使用code
向auth URL发出POST请求和Instagram身份验证中记录的client_secret
类似的东西:
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
String code = url.getQueryParameter("code");
// ...
}
});