Android 在将文本发布到tumblr时,我得到的消息未经授权
我在Android应用程序中使用以下代码将文本发布到tumblr:Android 在将文本发布到tumblr时,我得到的消息未经授权,android,authentication,authorization,tumblr,Android,Authentication,Authorization,Tumblr,我在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<NameVal
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();
}
}
我错过什么了吗?我有正确的访问令牌和密钥。检查你的标题、正文或博客名称,如果它等于null,你的响应将是401你首先需要在tumblr上创建一个博客,然后你就可以在该博客上发表文章。你需要手动创建一个博客,然后再在该博客上发表文章
HttpPost hpost = new HttpPost("http://api.tumblr.com/v2/blog/" + blogname.getText().toString() + ".tumblr.com/post");
将
.tumblr.com/post
替换为.tumblr.com/posts
您找到了此问题的解决方案吗?我也面临同样的问题。
HttpPost hpost = new HttpPost("http://api.tumblr.com/v2/blog/" + blogname.getText().toString() + ".tumblr.com/post");