0

我正在开发一个非常简单的 android twitter 应用程序,但是当我尝试在 twitter 上发布推文时,它给了我收到的身份验证为空错误,并且在 android 4.1 中它强制关闭我搜索网络但没有找到任何帮助的应用程序

enter public class StatusClass extends Activity implements OnClickListener{

private Button update;
Twitter twitter;
ConfigurationBuilder cb;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.update_status);
    update = (Button)findViewById(R.id.bUpdate);
    update.setOnClickListener(this);
    cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey("My_Consumer_key");
    cb.setOAuthConsumerSecret("My_Consumer_secret_key");
    cb.setOAuthAccessToken("My_Oath_access_token");
    cb.setOAuthAccessTokenSecret("My_Token_secret");
     twitter = new TwitterFactory(cb.build()).getInstance();   
}

@Override
public void onClick(View v) {



        String tweet="HELLO WORLD!";
        try {
            Status status = twitter.updateStatus(tweet);
        } catch (TwitterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }






}

}

 W/System.err( 1798):   at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.processAuthHeader(HttpURLConnectionImpl.java:1153)
4

1 回答 1

1

您是否尝试过以下代码?

AccessToken accessToken = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
OAuthAuthorization authorization = new OAuthAuthorization(ConfigurationContext.getInstance(), CONSUMER_KEY, CONSUMER_SECRET, accessToken);
Twitter twitter = new TwitterFactory().getInstance(authorization);

还可以尝试基本授权:

Configuration configuration = new ConfigurationBuilder()
.setOAuthConsumerKey("your_customer_key")
.setOAuthConsumerSecret("your_customer_secret")
.build();

Twitter twitter = new TwitterFactory(configuration).getInstance(new BasicAuthorization("username", "password"));
AccessToken token = twitter.getOAuthAccessToken();
于 2013-06-05T19:09:43.803 回答