2010-02-04 6 views
7

내 Android 애플리케이션이 자바 OAuth 라이브러리를 사용하며 Twitter에서 승인을 위해 here을 발견했습니다. 요청 토큰을 받고 토큰을 인증하고 승인을 얻을 수 있지만 브라우저가 응용 프로그램과 다시 연결하기 위해 콜백 URL을 시도하면 코드에서 제공하는 URL을 사용하지 않지만 등록하는 동안 제공된 URL을 사용합니다 트위터와 함께.Android에서 OAuth + Twitter : 콜백 실패

참고 :
1. 내 애플리케이션을 트위터에 등록 할 때 나는 가상의 콜백 URL (http://abz.xyc.com)을 제공하고 브라우저로 애플리케이션 유형을 설정했습니다.
2. 코드 "myapp"에 콜백 URL을 제공하고 Browable 범주 및 데이터 체계가 "myapp"인 활동에 대한 의도 필터를 추가했습니다.
3. 권한 부여시 호출되는 URL에 코드에 지정된 te 콜백 URL이 포함되어 있습니다.

내가 여기 잘못 생각한가요?

관련 코드 : 올바른 일을하고있는 트위터는 항상 등록 된 콜백 URL을 수용 의해 나사처럼

public class FirstActivity extends Activity 
{ 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     OAuthAccessor client = defaultClient(); 
     Intent i = new Intent(Intent.ACTION_VIEW); 
     i.setData(Uri.parse(client.consumer.serviceProvider.userAuthorizationURL + "?oauth_token=" 
       + client.requestToken + "&oauth_callback=" + client.consumer.callbackURL)); 

     startActivity(i); 

    } 

    OAuthServiceProvider defaultProvider() 
    { 
     return new OAuthServiceProvider(GeneralRuntimeConstants.request_token_URL, 
       GeneralRuntimeConstants.authorize_url, GeneralRuntimeConstants.access_token_url); 
    } 

    OAuthAccessor defaultClient() 
    { 
     String callbackUrl = "myapp:///"; 
     OAuthServiceProvider provider = defaultProvider(); 
     OAuthConsumer consumer = new OAuthConsumer(callbackUrl, 
       GeneralRuntimeConstants.consumer_key, GeneralRuntimeConstants.consumer_secret, 
       provider); 
     OAuthAccessor accessor = new OAuthAccessor(consumer); 

     OAuthClient client = new OAuthClient(new HttpClient4()); 
     try 
     { 
      client.getRequestToken(accessor); 
     } catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 

     return accessor; 
    } 

    @Override 
    protected void onResume() 
    { 
     // TODO Auto-generated method stub 
     super.onResume(); 

     Uri uri = this.getIntent().getData(); 
     if (uri != null) 
     { 
      String access_token = uri.getQueryParameter("oauth_token"); 
     } 
    } 

} 
// Manifest file 
<application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".FirstActivity" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
      <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="myapp"/> 
      </intent-filter> 
     </activity> 
</application> 

답변

11

Twitter는 OAuth 요청 (Twitter API Announce)에서 요청 된 콜백을 따르지 않으며 응용 프로그램 설정 ("localhost"는 허용되지 않음)에 지정된 콜백 URL로만 리디렉션됩니다.

나는 당신이 Oauth-callback-on-android을 확인했다고 가정합니다.

안드로이드는 독서의 조금 후
을 guesswork--, 나는 안드로이드 브라우저 MyApp를 리디렉션 참조 : /// 응용 프로그램과 나는이 맞춤형 URI 접두사를 좋아하지 않는다 트위터에 같은데요. 나는 안드로이드 개발자가 아니지만 내가 할 수있는 한 가지 제안은 웹상에서 "www.myapp.com"을 얻고 거기에 다시 리디렉션하는 것입니다.

그래서 http://www.myapp.com/redirect.aspx?oauth_token=abc에 OAuth는 반환이 있고 해당 페이지 내 경우 myapp:///oauth_token=... (원하는 결과)

+0

답장을 보내 주셔서 감사합니다. 1. 진술에 대한 참조를 인용 할 수 있습니까? "Twitter는 OAuth 요청에서 요청 된 콜백을 따르지 않으며 응용 프로그램 설정에 지정된 콜백 URL로 리디렉션됩니다 ("localhost "는 허용되지 않음).이에 따라 " 2. 네, 나는에 OAuth 콜백 - 온 - 안드로이드 질문을 확인했고 (예 : 브라우저) 내 응용 프로그램 유형을 설정했습니다. 다시 한 번 감사드립니다. 트위터 API에 – Samuh

+0

추가 링크를 발표합니다. –

+0

콜백의 OAuth에서 요구하는 경우 요청이 존중되지 않는 경우 내 애플리케이션을 다시 게시 승인으로 부르는 방법은 무엇입니까? 트위터는 Android 스타일의 URL을 수락하지 않으며이를 재정의해야합니다. 위의 경우 작동하지 않으면 대체 방법은 무엇입니까 도와주세요 .[10 당신이이 마지막 질문에 답한 후에 125 점 : – Samuh

0

그것은 나에게 보인다. 등록 된 URL을 변경할 수있는 방법이 있습니까? 다음에 Android 콜백을 다시 등록하고 시도해보십시오. 어떻게되는지보십시오.

+0

예, EDIT 응용 프로그램 설정 버튼을 클릭하여 등록 된 URL을 변경할 수 있습니다. 행운을 빌지 않고 URL의 두 가지 세트를 사용해 보았습니다. – Samuh

+0

아무런 문제없이 응용 프로그램을 다시 등록했는데 ... – Samuh

3

로 리디렉션, 나는이 작업이 :

String authURL = m_provider.retrieveRequestToken (m_consumer, CALLBACK_URL); 

을 그리고 매니페스트 :

<activity android:configChanges = "keyboardHidden|orientation" android:name = "xxxx.android.xxxxx"> 
     <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="myapp" android:host="tweet" /> 
     </intent-filter> 

이 경우 콜백 URL은 다음과 같습니다. myapp : // tweet

+0

내 응용 프로그램 이름은 myapp이란 무엇인지 알려주시겠습니까? 그리고 짹짹 대신 쓸 내용은 무엇입니까? –

0

내 문제는 내가 Twitter 앱을 만들었던 계정으로 로그인하려고 시도했기 때문이다. 개인 프로필로 로그인하면 콜백이 작동합니다 (지금까지).