2011-10-24 19 views
1

我需要你的幫助找出原因的回調URL不與我一起工作,因爲我不能FO回的onResume在活動爲什麼在oauth回調url不會將我重定向到android中的onResume()?

這裏是代碼我使用

public class OAuthTrialsActivity extends Activity { 
     /** Called when the activity is first created. */ 
     private static final String CONSUMER_KEY = "66aba0d1168566c364d86e6087bea04e04e9ff754"; 
     private static final String CONSUMER_SECRET = "aec138c913cb21763b4983de77683a04"; 
     private static final int CALL_BACK = 1; 

     private static String ACCESS_KEY = null; 
     private static String ACCESS_SECRET = null; 


     private static final String REQUEST_URL = "http://yakhabar.tawasoldev.com/index.php/api/requestToken"; 
     private static final String ACCESS_TOKEN_URL = "http://yakhabar.tawasoldev.com//index.php/api/accessToken"; 
     private static final String AUTH_URL = "http://yakhabar.tawasoldev.com/index.php/api/AuthorizeApp"; 
     private static final String CALLBACK_URL = "http://localhost/app.php?third=true"; 

     private static CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(
        CONSUMER_KEY, CONSUMER_SECRET); 
     private static CommonsHttpOAuthProvider provider = new CommonsHttpOAuthProvider(
     REQUEST_URL, ACCESS_TOKEN_URL, AUTH_URL); 


     Button btnLogin; 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 
      provider.setOAuth10a(true); 
      btnLogin = (Button) findViewById(R.id.btnLogin); 
      btnLogin.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       try { 
         String authURL = provider.retrieveRequestToken(
              consumer, CALLBACK_URL); 

        Log.d("OAuthTwitter authURL", authURL); 
        startActivity(new Intent(Intent.ACTION_VIEW, Uri 
              .parse(authURL))); 


       } catch (OAuthMessageSignerException e) { 
       e.printStackTrace(); 
       } catch (OAuthNotAuthorizedException e) { 
       e.printStackTrace(); 
       } catch (OAuthExpectationFailedException e) { 
       e.printStackTrace(); 
       } catch (OAuthCommunicationException e) { 
       e.printStackTrace(); 
       } 
       } 
      }); 
     } 
@Override 
    public void onResume() { 
     super.onResume(); 
     Uri uri = this.getIntent().getData(); 
     Log.d("ana shoftha","ahmed"+uri); 
     if (uri != null && uri.toString().startsWith(CALLBACK_URL)) { 
      Log.d("ana shoftha","ahmed"); 
      Log.d("OAuthTwitter uri", uri.toString()); 
      String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER); 
      Log.d("OAuthTwitter verifier", verifier); 
      try { 

       provider.retrieveAccessToken(consumer, verifier); 
       ACCESS_KEY = consumer.getToken(); 
       ACCESS_SECRET = consumer.getTokenSecret(); 

       Log.d("OAuthTwitter key ", ACCESS_KEY); 
       Log.d("OAuthTwitter secret", ACCESS_SECRET); 

      } catch (OAuthMessageSignerException e) { 
       e.printStackTrace(); 
      } catch (OAuthNotAuthorizedException e) { 
       e.printStackTrace(); 
      } catch (OAuthExpectationFailedException e) { 
       e.printStackTrace(); 
      } catch (OAuthCommunicationException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
} 

這裏是清單

<activity android:name=".OAuthTrialsActivity" android:label="@string/app_name" 
      > 
      <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:scheme="http" android:host="localhost" /> 
      </intent-filter> 
     </activity> 

服務指引我到回調URL與驗證,但我可以提取它,因爲我不回去的活動

任何人都可以幫助,並給我一個解決方案請

回答

0

我今天遇到了同樣的問題。在Twitter上,我沒有在設置頁面上指定回叫網址。我補充說,我的onReceive開始工作。該網址可以是任何內容,而不是特定於您的應用程序。希望這可以幫助!

+0

你有沒有在android ICS中檢查過 – nicky

相關問題