【发布时间】:2016-02-12 23:55:59
【问题描述】:
我正在使用 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
}
}
}
这是我处理意图过滤器的清单 sn-p:
<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>
【问题讨论】:
标签: android redirect instagram-api