2

我正在 Android 应用程序中开发雅虎登录集成并返回主活动。我已经完成了雅虎集成的所有步骤。我花了几天时间在 android 中搜索雅虎集成,但我找不到正确的方法。当我运行此代码并正确登录雅虎电子邮件时,当我点击同意按钮时,它总是会出现 call_Back URL . 请任何人都可以帮助mi。这是我的代码

public class RequestTokaenActivity2 extends Activity
{
    private OAuthConsumer consumer;
    private OAuthProvider provider;
    private SharedPreferences yahooPrefs;
    private CommonsHttpOAuthConsumer myConsumer;
    private CommonsHttpOAuthProvider myProvider;
    private String requestToken;
    private String accessToken;

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        try
        {
            consumer=new CommonsHttpOAuthConsumer(c1.CONSUMER_KEY,c1.CONSUMER_SECRET);

            consumer.setMessageSigner(new HmacSha1MessageSigner());
            HttpClient httpCliet=new DefaultHttpClient();


            provider=new CommonsHttpOAuthProvider(c1.REQUEST_URL,c1.ACCESS_URL,c1.AUTHORIZE_URL,httpCliet);
            provider.setOAuth10a(true);
            String strUrl=provider.retrieveRequestToken(consumer,c1.OAUTH_CALLBACK_URL);
            requestToken=consumer.getToken();
            startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(strUrl)));

        }

        catch(Exception ex)
        {
            Toast.makeText(getApplicationContext(),ex.getMessage(),Toast.LENGTH_LONG).show();
            Log.e(ex.getMessage(), ex.toString());

        }



    }

    @Override

    public void onNewIntent(Intent intent)
    {
        super.onNewIntent(intent);
        yahooPrefs=PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        final Uri uri=intent.getData();

        if(uri!=null && uri.getScheme().equals(c1.OAUTH_CALLBACK_SCHEME))
        {
            Log.i(c1.TAG, "Callback received : " + uri);
            Log.i(c1.TAG, "Retrieving Access Token");
            getAccessToken(uri);
        }

    }


    private void getRequestToken()
    {
        try
        {
            String url=provider.retrieveRequestToken(consumer, c1.OAUTH_CALLBACK_URL);
            Intent i=new Intent(Intent.ACTION_VIEW , Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND );
            this.startActivity(i);


        }
        catch(Exception e1)
        {
            e1.printStackTrace();
            Log.e(c1.TAG, "Error retrieving request token", e1);
        }
    }

    private void getAccessToken(Uri uri)
    {

        final String oauthVerifier=uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
        final Editor edit=yahooPrefs.edit();
        edit.putString(OAuth.OAUTH_TOKEN,consumer.getToken());
        edit.putString(OAuth.OAUTH_TOKEN_SECRET,consumer.getTokenSecret());
        edit.commit();

        String token=yahooPrefs.getString(OAuth.OAUTH_TOKEN, "");
        String secret=yahooPrefs.getString(OAuth.OAUTH_TOKEN_SECRET,"");

        consumer.setTokenWithSecret(token, secret);
        this.startActivity(new Intent(this,OAuthMain.class));
        Log.i(c1.TAG, "Access Token Retrieved");

    }

}






  public class c1 
    {
        public static final String CONSUMER_KEY     = "xxxxxxxxxx";
        public static final String CONSUMER_SECRET  = "xxxxxxxxxx";


        public static final String SCOPE            = "http://social.yahooapis.com/v1/user/";

        public static final String REQUEST_URL      = "https://api.login.yahoo.com/oauth/v2/get_request_token";

        //https://api.login.yahoo.com/oauth/v2/

        public static final String ACCESS_URL       = "https://api.login.yahoo.com/oauth/v2/get_access_token"; 
        //https://api.login.yahoo.com/oauth/v2/get_token"

        public static final String AUTHORIZE_URL    = "https://api.login.yahoo.com/oauth/v2/request_auth";
        //https://api.login.yahoo.com/oauth/v2/request_auth"
        //public static final String UNAUTHORIZE_URL  = "https://accounts.google.com/o/oauth2/revoke";

        public static final String GET_CONTACTS_FROM_YAHOO_REQUEST="http://social.yahooapis.com/v1/user/{guid}/contacts";

        public static final String ENCODING = "UTF-8";

        public static final String  OAUTH_CALLBACK_SCHEME   = "http";
        public static final String  OAUTH_CALLBACK_HOST     = "www.bcod.co.in";
        public static final String  OAUTH_CALLBACK_URL      = OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST;
        public static final String  APP_NAME                = "Demo_Oauth1";
        public static final String  TAG = null;

    }
4

0 回答 0