简体   繁体   English

twitter4j找不到身份验证挑战

[英]twitter4j no authentication challenges found

Been trying to use twitter4j to post a tweet for couple days now without luck, what i want to do is for a person to post their new top score on their timeline from the app at the end of a round. 一直试图使用twitter4j发布推文已有两天了,但是没有运气,我想做的是一个人在回合结束时从应用程序在其时间轴上发布其新的最高分。 Here is my code 这是我的代码

          @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tweetr);
    Button tweetr = (Button)findViewById(R.id.tweetr);

    //create a new twitter configuration using user details
    tweetTwitter = new TwitterFactory().getInstance();
    tweetTwitter.setOAuthConsumer(TWIT_KEY, TWIT_SECRET);


        //create a twitter instance
   // tweetTwitter = new TwitterFactory(twitConf).getInstance();



    tweetr.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {


          dt.execute();

        }
    });



}


public class TweetTask extends AsyncTask<Object, Void, String> {
    @Override
    protected String doInBackground(Object... values) {
        /* try {
            //requestToken = tweetTwitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
        } catch (TwitterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
        */
        try {
            requestToken = tweetTwitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
            String authUrl = requestToken.getAuthenticationURL();
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
        } catch (TwitterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


      return null;
    }


    @Override
    protected void onPostExecute(String result) {
        Log.d("URI", "DONE");
        super.onPostExecute(result);
    }




}



@Override
protected void onResume() {
    super.onResume();
    final Uri uri = getIntent().getData();
    if(uri != null ){

                Log.d("URI", uri.toString());

                Thread th = new Thread(){
                    public void run(){
                        try {
                            String verifier = uri.getQueryParameter("oauth_verifier");
                            String oauthToken = uri.getQueryParameter("oauth_token");

                            RequestToken reqToken = tweetTwitter.getOAuthRequestToken(oauthToken,verifier); 


                            AccessToken accessToken = tweetTwitter.getOAuthAccessToken(reqToken);
                            String token = accessToken.getToken(), secret = accessToken.getTokenSecret();

                        } catch (TwitterException ex) {
                            Log.e("Main.onNewIntent", "" + ex.getMessage());
                        }


                    }};
                    th.start();
      }else
        Log.d("URI", "FAILED");         


    }

} }

This is my error print out 这是我的错误打印出来

10-23 15:35:18.661: D/TWIT ER(2392): No authentication challenges foundRelevant discussions can be found on the Internet at:

参考Twitter4J的javadoc

In order to get access acquire AccessToken using xAuth, you must apply by sending an email to api@twitter.com — all other applications will receive an HTTP 401 error.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM