我的Android应用程序使用Java OAuth库,在Twitter上找到here进行授权。我能够获得请求令牌,授权令牌并获得确认,但是当浏览器尝试回拨url以重新与我的应用程序连接时,它不会使用我在代码中提供的URL,而是使用我在注册时提供的URL与Twitter。Android上的OAuth + Twitter:回拨失败
注:
1.当我的注册与Twitter的应用程序,我提供一个假想的回调网址:http://abz.xyc.com和设置应用程序类型的浏览器。
2.我在我的代码“myapp”中提供了一个回调网址,并为我的活动添加了一个意向过滤器,将Browsable类别和数据方案添加为“myapp”。
3.授权时调用的URL确实包含te代码中指定的回调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>
感谢您的回复。 1.能否请你举你的语句引用: “推特不认可的OAuth请求,请求回调,只会重定向到应用程序设置指定的回调URL(注意,‘本地主机’是不允许的)。“ 2.是的,我做了检查OAuth的回调上Android的问题,并且已经设置我的应用程序类型(即浏览器),因此,再次 感谢。 – Samuh 2010-03-08 13:35:04
添加链接的Twitter API公布。 – 2010-03-08 13:47:34
如果在回调要求的OAuth请求没有兑现,那么我怎么称呼我的应用程序后授权?Twitter不接受Android风格的URL,这些需要被覆盖。如果上述不工作有什么替代方法? 请帮助。 [你得到10现在点; 125回答完这个最后一个问题后:P] – Samuh 2010-03-09 09:52:52