1
我試圖創建一個應用程序,其中的功能之一是添加用戶登錄/註銷。錯誤描述:無法返回提供的redirect_uri
我跟隨這名:https://api.stackexchange.com/docs/authentication
所以我在我的活動按鈕,點擊該按鈕將其重定向你的瀏覽器登錄到堆棧溢出的網站。我想在用戶登錄後返回到我的應用程序。但它說「不能返回到提供REDIRECT_URI」
這裏的我AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vivek.stack.client">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".retro.Login"
android:label="@string/app_name"
android:configChanges="keyboard|orientation|screenSize">
<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="aahost"
android:scheme="bbscheme" />
</intent-filter>
</activity>
<activity android:name=".Mine">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"></category>
<action android:name="android.intent.action.MAIN"></action>
</intent-filter>
</activity>
</application>
</manifest>
我的登錄類:
package com.vivek.stack.client.retro;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import com.vivek.stack.client.R;
/**
* Created by Shiva on 14-04-2016.
*/
public class Login extends AppCompatActivity {
RelativeLayout relativeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
relativeLayout = (RelativeLayout)findViewById(R.id.snack);
Button loginButton =(Button) findViewById(R.id.loginbutton);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String uri = "https://stackexchange.com/oauth?\n" +
"scope=private_info&\n" +
"redirect_uri=bbscheme://aahost&\n"+
"client_id=" ;
Intent intent = new Intent(
Intent.ACTION_VIEW,
Uri.parse(uri));
if(intent.resolveActivity(getPackageManager())!=null)
startActivity(intent);
}
});
}
@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
Log.i("MYCODECODE" , code);
Snackbar.make(relativeLayout ,code , Snackbar.LENGTH_LONG).show();
} else if (uri.getQueryParameter("error") != null) {
// show an error message here
Log.i("NO CODE" , "NO CODE");
Snackbar.make(relativeLayout ,"we did not get" , Snackbar.LENGTH_LONG).show();
}
}
}
}
它應該返回到應用程序,一旦登錄成功。
我希望我能得到一些幫助。 :( –