2012-09-28 19 views
1

同時發佈文字來tumblr我得到的味精不是401我用下面的代碼來發布文字在我的Android應用程序tumblr無權

public class Snippet { 
    HttpPost hpost = new HttpPost("http://api.tumblr.com/v2/blog/" + blogname.getText().toString() + ".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)); 
    try 
    { 
     hpost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
    } 
    catch (UnsupportedEncodingException e) 
    { 
     debug += e.toString(); 
    } 
    consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); 
    consumer.setTokenWithSecret(token, secret); 
    try 
    { 
     consumer.sign(hpost); 
    } catch (OAuthMessageSignerException e) 
    { 
     debug += e.toString(); 
    } catch (OAuthExpectationFailedException e) 
    { 
     debug += e.toString(); 
    } catch (OAuthCommunicationException e) 
    { 
     debug += e.toString(); 
    } 
    DefaultHttpClient client = new DefaultHttpClient(); 
    HttpResponse resp = null; 
    try 
    { 
     resp = client.execute(hpost); 
    } catch (ClientProtocolException e) 
    { 
     debug += e.toString(); 
    } catch (IOException e) 
    { 
     debug += e.toString(); 
    } 
    String result = null; 
    try { 
     result = EntityUtils.toString(resp.getEntity()); 
    } catch (ParseException e) 
    { 
     debug += e.toString(); 
    } catch (IOException e) 
    { 
     debug += e.toString(); 
    } 
} 

然後我得到以下結果:

{"meta":{"status":401,"msg":"Not Authorized"},"response":[]} 

我錯過了什麼嗎?我有正確的訪問令牌和密鑰。

+0

更換.tumblr.com/post你有這個問題的解決方案?我面臨着同樣的問題。 –

回答

0

檢查標題,正文或博客的名字,如果它等於null你respons將401

0

您首先需要創建在tumblr一個博客,那麼你將能夠張貼上blog.You manulaly需要創建一個博客,那麼你上張貼博客..

0
HttpPost hpost = new HttpPost("http://api.tumblr.com/v2/blog/" + blogname.getText().toString() + ".tumblr.com/post"); 

通過.tumblr.com/posts

相關問題