2011-10-11 72 views
2

我在我的應用程序中使用單點登錄(http://developers.facebook.com/docs/mobile/android/build/)。它似乎在模擬器上正常工作(我成功登錄並獲取access_token)。但在我的Nexus S中,webview顯示,但我總是「登錄失敗」。Facebook sdk(單一登錄)沒有在設備上工作

有我的代碼:

((Button)findViewById(R.id.BtnFacebook)).setOnClickListener(new OnClickListener(){ 

     public void onClick(View v) { 

      //startActivity(intentLoginFacebook); 

      facebook.authorize(Login.this, new String[] {"user_about_me","user_activities","user_birthday","user_education_history","user_events","user_groups","user_hometown","user_interests","user_likes","user_location","user_religion_politics","user_status","user_website","user_work_history","read_requests","read_stream","friends_events","email","create_event","manage_friendlists","offline_access","rsvp_event"}, new DialogListener() { 
       @Override 
       public void onComplete(Bundle values) { 

        String id = ""; 
        String access_token = facebook.getAccessToken(); 
        System.out.println("ACCESSTOKENNNN:" + access_token); 

        try { 
         String response = facebook.request("me"); 

         JSONObject obj = new JSONObject(response); 
         id = obj.getString("id"); 
         System.out.println("response: "+response); 

        } catch (IOException ex) { 
         Log.d("Facebook", ex.getMessage()); 
        } catch (Exception e) { 
         Log.d("Facebook", e.getMessage()); 
        } 


        //Verification du login/password 
        new LoginFacebook().execute(id,access_token); 
        System.out.println("IDDDDDDDD:" + id);    

       } 

       @Override 
       public void onFacebookError(FacebookError error) { 
        Toast.makeText(getApplicationContext(), "Facebook error: login failed", Toast.LENGTH_LONG).show(); 

       } 

       @Override 
       public void onCancel() { 
       } 

       @Override 
       public void onError(DialogError e) { 
        // TODO Auto-generated method stub 
        Toast.makeText(getApplicationContext(), "Login failed", Toast.LENGTH_LONG).show(); 

       } 
      }); 

     } 
      }); 

感謝您的幫助!

+0

清除瀏覽器Cookie和運行應用程序用乾淨的構建項目 –

+0

沒有工作.... – user420574

+0

@ user420574你能解釋一下如何ü創建哈希鍵..問題會with Hash Key .. – Venky

回答

0

很有可能SDK會將您的access_token和expires_in參數存儲在SharedPreferences中。您需要記錄詳細的錯誤。如果您在API調用中遇到OAuth異常,則需要從SharedPreferences中刪除access_token,然後重新授權。

希望這有助於再次

+0

SDK不在SharedPreferences中存儲access_token .. – user420574

相關問題