我正在使用 Google Blogger API 在我创建的博客中以编程方式创建帖子。我正在使用下面的代码尝试创建新帖子,但它没有添加新博客
编码:
private void addPost(){
new Thread (()->{
String mUserId = "MY_BLOGGER_POST_ID_HERE";
String mYApiKey = "MY_API_KEY";
String Authorization = "SOME_CHARACTERS_AND.apps.googleusercontent.com_HERE";
final JSONObject obj = new JSONObject();
obj.put("id", mUserId);
final JSONObject requestBody = new JSONObject();
requestBody.put("kind", "blogger#post");
requestBody.put("blog", obj);
requestBody.put("title", "TestingTheBlogOneTwo");
requestBody.put("content", "ContentExample");
DefaultHttpClient httpClient = new DefaultHttpClient();
final HttpPost request = new HttpPost("https://www.googleapis.com/blogger/v3/blogs/" + mUserId + "/posts?key=" + mYApiKey + "");
request.addHeader("Authorization", Authorization);
request.addHeader("Content-Type", "application/json");
request.setEntity(new StringEntity(requestBody.toString()));
HttpResponse response = httpClient.execute(request);
if (response.getStatusLine().getStatusCode() != 200){
Toast.makeText(getApplicationContext(), "status code " + response.getStatusLine().getStatusCode(), Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplicationContext(), "done: ", Toast.LENGTH_SHORT).show();
}
}).start();
}
但它没有添加任何帖子
•这是使用Blogger Api 添加帖子的正确方法吗?
•我遗漏了什么吗?*请问我做错了什么。
任何帮助将不胜感激。提前致谢。
更新:应用程序没有崩溃,也没有添加新博客