0

这是代码,什么是相关的。我定义了密钥、秘密和回调变量。我正在使用这些库版本:SocialLibBeta2_2.jar、signpost-core-1.2.1.2.jar、signpost-commonshttp4-1.2.1.2.jar、scribe-0.6.7-SNAPSHOT.jar。

import com.expertiseandroid.lib.sociallib.connectors.SocialNetworkHelper;
import com.expertiseandroid.lib.sociallib.connectors.TwitterConnector;
import com.expertiseandroid.lib.sociallib.exceptions.NotAuthentifiedException;
import com.expertiseandroid.lib.sociallib.model.twitter.TwitterUser;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.scribe.oauth.Token;
import org.xml.sax.SAXException;

import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;

public void SendTweet()
{
TwitterConnector twitter = SocialNetworkHelper.createTwitterConnector(CONS_KEY, CONS_SEC, CALLBACK);

try {
        twitter.requestAuthorization(this);
    } catch (OAuthMessageSignerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthNotAuthorizedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthExpectationFailedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthCommunicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        twitter.authorize(this);
    } catch (OAuthMessageSignerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthNotAuthorizedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthExpectationFailedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthCommunicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Token at = twitter.getAccessToken();
    String token = at.getToken(); 
    String secret = at.getSecret();

    Token myAccessToken = new Token(token, secret);
    twitter.authentify(myAccessToken);

    try {
        twitter.tweet("Test tweet");
    } catch (OAuthMessageSignerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthExpectationFailedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthCommunicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NotAuthentifiedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   
}

这是错误:

04-17 19:05:18.958: E/AndroidRuntime(932): FATAL EXCEPTION: main
04-17 19:05:18.958: E/AndroidRuntime(932): java.lang.NoSuchMethodError: oauth.signpost.commonshttp.CommonsHttpOAuthProvider.retrieveRequestToken
04-17 19:05:18.958: E/AndroidRuntime(932):  at com.expertiseandroid.lib.sociallib.connectors.TwitterConnector.requestAuthorization(TwitterConnector.java:287)
04-17 19:05:18.958: E/AndroidRuntime(932):  at com.sirva.mymc.JournalActivity.SendTweet(JournalActivity.java:247)
04-17 19:05:18.958: E/AndroidRuntime(932):  at com.sirva.mymc.JournalActivity$1$1.onClick(JournalActivity.java:135)
04-17 19:05:18.958: E/AndroidRuntime(932):  at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:873)
04-17 19:05:18.958: E/AndroidRuntime(932):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
04-17 19:05:18.958: E/AndroidRuntime(932):  at android.widget.ListView.performItemClick(ListView.java:3513)
04-17 19:05:18.958: E/AndroidRuntime(932):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
04-17 19:05:18.958: E/AndroidRuntime(932):  at android.os.Handler.handleCallback(Handler.java:587)
04-17 19:05:18.958: E/AndroidRuntime(932):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-17 19:05:18.958: E/AndroidRuntime(932):  at android.os.Looper.loop(Looper.java:130)
04-17 19:05:18.958: E/AndroidRuntime(932):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-17 19:05:18.958: E/AndroidRuntime(932):  at java.lang.reflect.Method.invokeNative(Native Method)
04-17 19:05:18.958: E/AndroidRuntime(932):  at java.lang.reflect.Method.invoke(Method.java:507)
04-17 19:05:18.958: E/AndroidRuntime(932):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-17 19:05:18.958: E/AndroidRuntime(932):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-17 19:05:18.958: E/AndroidRuntime(932):  at dalvik.system.NativeStart.main(Native Method)

正在爆炸的 TwitterConnector 函数如下所示:

public void requestAuthorization(Context ctx) throws OAuthMessageSignerException, OAuthNotAuthorizedException, OAuthExpectationFailedException, OAuthCommunicationException 
{
  String authUrl = httpOauthprovider.retrieveRequestToken(httpOauthConsumer, callback);
  ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
}

protected TwitterConnector(String consumerKey, String consumerSecret, String callback){
  this(consumerKey, consumerSecret, callback, "");
}

protected TwitterConnector(String consumerKey, String consumerSecret, String callback, String twitPicKey){
  this.authentified = false;
  this.reader = new TwitterReader();
  this.twitPicKey = twitPicKey;
  this.callback = callback;
  httpOauthConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
  httpOauthprovider = new CommonsHttpOAuthProvider(TWITTER_REQUEST, TWITTER_ACCESS, AUTHORIZE);

}

这是一个快速测试应用程序,以确保没有其他库有问题

package com.test;

import android.app.Activity;
import android.os.Bundle;
import com.expertiseandroid.lib.sociallib.connectors.SocialNetworkHelper;
import com.expertiseandroid.lib.sociallib.connectors.TwitterConnector;
import com.expertiseandroid.lib.sociallib.exceptions.NotAuthentifiedException;
import com.expertiseandroid.lib.sociallib.model.twitter.TwitterUser;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.scribe.oauth.Token;
import org.xml.sax.SAXException;

import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;

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

    String CONS_KEY = "xxxxxxxxxxxxxxxxxxx";
    String CONS_SEC = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
    String CALLBACK = "http://xxxx.com";

    TwitterConnector twitter = SocialNetworkHelper.createTwitterConnector(CONS_KEY, CONS_SEC, CALLBACK);

    try {
        twitter.requestAuthorization(TestActivity.this);
    } catch (OAuthMessageSignerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthNotAuthorizedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthExpectationFailedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthCommunicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        twitter.authorize(this);
    } catch (OAuthMessageSignerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthNotAuthorizedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthExpectationFailedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthCommunicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Token at = twitter.getAccessToken();
    String token = at.getToken(); 
    String secret = at.getSecret();

    Token myAccessToken = new Token(token, secret);
    twitter.authentify(myAccessToken);

    try {
        twitter.tweet("Test tweet");
    } catch (OAuthMessageSignerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthExpectationFailedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OAuthCommunicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NotAuthentifiedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   
}

}

运行这个时我得到同样的错误。TestActivity.this 是一个有效的上下文,我可以访问方法 requestAuthorization 但它再次显示 NoSuchMethodError。测试项目中包含的库:commons-codec-1.6.jar、scribe-0.6.6.jar(也试过 0.6.7)、signpost-commonshttp4-1.2.1.2.jar、signpost-core-1.2.1.2.jar、路标-jetty6-1.2.1.2.jar,SocialLibBeta2_2.jar。

这也是清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="10" />

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".TestActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>
4

2 回答 2

0

我选择只使用 Scribe。SocialLib 给我带来了太多问题。

于 2012-04-20T12:37:12.563 回答
0

我认为您错过了应该包含在项目中的 lib,这就是为什么您会收到此错误的原因,您应该从此处下载这 3 个库并同时下载lib,否则您将再次获得另一个异常

于 2012-04-17T20:37:02.560 回答