1

我有一段代码可以获取用于检索 RequestToken 的 url。

/*
TAG = "my_debugger";
CONSUMER_KEY        = "anonymous";
CONSUMER_SECRET     = "anonymous";
SCOPE               = "https://www.google.com/m8/feeds/";
REQUEST_URL         = "https://www.google.com/accounts/OAuthGetRequestToken";
ACCESS_URL          = "https://www.google.com/accounts/OAuthGetAccessToken";  
AUTHORIZE_URL       = "https://www.google.com/accounts/OAuthAuthorizeToken";
GET_CONTACTS_FROM_GOOGLE_REQUEST = "https://www.google.com/m8/feeds/contacts/default/full?alt=json";    
ENCODING                = "UTF-8";
OAUTH_CALLBACK_SCHEME   = "non";
OAUTH_CALLBACK_HOST     = "callback";
OAUTH_CALLBACK_URL      = OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST;
APP_NAME                = "NoN";
*/

try {
    consumer = new CommonsHttpOAuthConsumer(C.CONSUMER_KEY, C.CONSUMER_SECRET);
    provider = new CommonsHttpOAuthProvider(
                C.REQUEST_URL  + "?scope=" + URLEncoder.encode(C.SCOPE, C.ENCODING) + "&xoauth_displayname=" + C.APP_NAME,
                C.ACCESS_URL,
                C.AUTHORIZE_URL);
    String url = provider.retrieveRequestToken(consumer, C.OAUTH_CALLBACK_URL);
}
catch (Exception e) {
    Log.e(C.TAG, "Error retrieving request token", e);
}

但是语法 provider.retrieveRequestToken 不起作用,因此此代码返回 logerror。

这是一段Logcat:

08-01 13:06:58.837: D/myDebugger(2382): getRequestToken() called
08-01 13:06:59.557: D/dalvikvm(2382): GC_FOR_ALLOC freed 196K, 10% free 2823K/3136K, paused 43ms, total 57ms
08-01 13:06:59.677: E/myDebugger(2382): Error retrieving request token
08-01 13:06:59.677: E/myDebugger(2382): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: null
08-01 13:06:59.677: E/myDebugger(2382):     at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
08-01 13:06:59.677: E/myDebugger(2382):     at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
08-01 13:06:59.677: E/myDebugger(2382):     at sg.vinova.vss.group5.non.activity.RequestTokenActivity.getRequestToken(RequestTokenActivity.java:38)
08-01 13:06:59.677: E/myDebugger(2382):     at sg.vinova.vss.group5.non.activity.RequestTokenActivity.onCreate(RequestTokenActivity.java:32)
08-01 13:06:59.677: E/myDebugger(2382):     at android.app.Activity.performCreate(Activity.java:5133)
08-01 13:06:59.677: E/myDebugger(2382):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-01 13:06:59.677: E/myDebugger(2382):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-01 13:06:59.677: E/myDebugger(2382):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-01 13:06:59.677: E/myDebugger(2382):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-01 13:06:59.677: E/myDebugger(2382):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-01 13:06:59.677: E/myDebugger(2382):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 13:06:59.677: E/myDebugger(2382):     at android.os.Looper.loop(Looper.java:137)
08-01 13:06:59.677: E/myDebugger(2382):     at android.app.ActivityThread.main(ActivityThread.java:5103)
08-01 13:06:59.677: E/myDebugger(2382):     at java.lang.reflect.Method.invokeNative(Native Method)
08-01 13:06:59.677: E/myDebugger(2382):     at java.lang.reflect.Method.invoke(Method.java:525)
08-01 13:06:59.677: E/myDebugger(2382):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-01 13:06:59.677: E/myDebugger(2382):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-01 13:06:59.677: E/myDebugger(2382):     at dalvik.system.NativeStart.main(Native Method)
08-01 13:06:59.677: E/myDebugger(2382): Caused by: android.os.NetworkOnMainThreadException
08-01 13:06:59.677: E/myDebugger(2382):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1133)
08-01 13:06:59.677: E/myDebugger(2382):     at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
08-01 13:06:59.677: E/myDebugger(2382):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
08-01 13:06:59.677: E/myDebugger(2382):     at java.net.InetAddress.getAllByName(InetAddress.java:214)
08-01 13:06:59.677: E/myDebugger(2382):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
08-01 13:06:59.677: E/myDebugger(2382):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-01 13:06:59.677: E/myDebugger(2382):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-01 13:06:59.677: E/myDebugger(2382):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
08-01 13:06:59.677: E/myDebugger(2382):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-01 13:06:59.677: E/myDebugger(2382):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-01 13:06:59.677: E/myDebugger(2382):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-01 13:06:59.677: E/myDebugger(2382):     at oauth.signpost.commonshttp.CommonsHttpOAuthProvider.sendRequest(CommonsHttpOAuthProvider.java:64)
08-01 13:06:59.677: E/myDebugger(2382):     at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:177)
08-01 13:06:59.677: E/myDebugger(2382):     ... 17 more
08-01 13:06:59.928: W/EGL_emulation(2382): eglSurfaceAttrib not implemented
08-01 13:07:00.657: I/ActivityManager(289): Displayed sg.vinova.vss.group5.non/.activity.RequestTokenActivity: +1s867ms    

我真的很感谢你能提供的任何帮助..

4

0 回答 0