2016-04-13 18 views
1

Özelliklerden birinin kullanıcı girişi/oturumu eklemek için bir uygulama oluşturmaya çalışıyorum. Bunu takip ediyorumHata açıklaması: Sağlanan redirect_uri'ye geri dönülemiyor

: https://api.stackexchange.com/docs/authentication

Yani ben o yığın taşması web sitesinden giriş için tarayıcıya yönlendirir o düğmeye tıklandığında, benim aktivitesinde bir düğme vardır. Kullanıcı oturum açtığında uygulamamıza geri dönmek istiyorum. ama burada

onun benim 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> 

Benim Girişi sınıfı 'sağlanan redirect_uri dönmek Can not' diyor:

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(); 

      } 
     } 
    } 


} 

giriş başarılı olduğunda yeniden app dönmelidir.

+0

Umarım biraz yardım alabilirim. :( –

cevap

1

Kendi sorumu yanıtlama.

Çözüm, yalnızca android:host ve android:scheme ürününüzün, uygulamanızı kaydederken verdiğiniz redirect_uri ile eşleştiğinden emin olun.