Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用访问令牌和令牌密码在android应用程序中发布到tumblr_Android_Tumblr - Fatal编程技术网

使用访问令牌和令牌密码在android应用程序中发布到tumblr

使用访问令牌和令牌密码在android应用程序中发布到tumblr,android,tumblr,Android,Tumblr,我正在尝试使用访问令牌在tumblr上发布文本。这些访问令牌是我从web应用程序的web服务获得的。请帮忙 这是我的代码,它在执行身份验证错误后显示此消息:无法响应任何这些挑战 String token = list.get(i).getAccess_token(); String tokenSecret = list.get(i).getAccess_token_secret(); System.

我正在尝试使用访问令牌在tumblr上发布文本。这些访问令牌是我从web应用程序的web服务获得的。请帮忙

这是我的代码,它在执行身份验证错误后显示此消息:无法响应任何这些挑战

                String token = list.get(i).getAccess_token();
                String tokenSecret = list.get(i).getAccess_token_secret();

                System.out.println("token :"+token);
                System.out.println("token secret :"+tokenSecret);


                HttpPost hpost = new HttpPost("http://api.tumblr.com/v2/blog/" +list.get(i).getUser_Name()+ ".tumblr.com/post");

                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("type", "text"));
                nameValuePairs.add(new BasicNameValuePair("title", title));
                nameValuePairs.add(new BasicNameValuePair("body", body));

                CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(Tumblr.TUMBLR_CONSUMERKEY, Tumblr.TUMBLR_SECRETKEY);
                consumer.setTokenWithSecret(token, tokenSecret);

                try {
                    consumer.sign(hpost);
                } 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();
                }

                DefaultHttpClient client = new DefaultHttpClient();
                HttpResponse resp = null;

                try {
                    resp = client.execute(hpost);
                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }

以下代码适用于我:

public class PostToTumblr extends AsyncTask<String, String, String> {
        private String userName;
        ProgressDialog progressDlg;
        int pos;
        CommonsHttpOAuthConsumer oAuthConsumer;
        CommonsHttpOAuthProvider oAuthprovider;
        TumblrUser user;

        public PostToTumblr(TumblrUser user) {
            this.user= user;
            progressDlg = new ProgressDialog(mContext);
            progressDlg.setMessage("Posting Message ");

            this.userName = user.getName();
            oAuthConsumer = new CommonsHttpOAuthConsumer(Const.CONSUMER_KEY,
                    Const.CONSUMER_SECRET);
            oAuthConsumer.setTokenWithSecret(user.getToken(), user.getSecret());

            oAuthprovider = new CommonsHttpOAuthProvider(Const.REQUEST_URL,
                    Const.ACCESS_URL, Const.AUTHORIZE_URL);
            oAuthprovider.setOAuth10a(true);

        }

        protected void onCancelled() {
            progressDlg.cancel();
        }

        protected void onPreExecute() {
            super.onPreExecute();
            progressDlg.show();
        }

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            progressDlg.dismiss();

        }

        @Override
        protected String doInBackground(String... params) {
            try {
                oAuthprovider.retrieveAccessToken(oAuthConsumer, user.getSessionUri().getQueryParameter("oauth_verifier"));
            } catch (OAuthMessageSignerException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (OAuthNotAuthorizedException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (OAuthExpectationFailedException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (OAuthCommunicationException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            DefaultHttpClient client = new DefaultHttpClient();
            HttpResponse resp = null;
            String result = null;
            HttpPost hpost = new HttpPost("http://api.tumblr.com/v2/blog/"
                    + userName + ".tumblr.com/post");
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("type", "photo"));
            nameValuePairs.add(new BasicNameValuePair("caption",
                    "hello final message for testing"));
            nameValuePairs.add(new BasicNameValuePair("source",
                    "http://www.gstatic.com/webp/gallery/1.jpg"));

            try {
                hpost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                oAuthConsumer.sign(hpost);
                resp = client.execute(hpost);
                result = EntityUtils.toString(resp.getEntity());
                Log.v("result >>", result);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } 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 (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    }

你有什么解决办法吗。我还在等待答案