我想使用 Blogger API 将帖子添加到我的博客。我成功获得了使用 Blogger API 的权利,并在 Google API 控制台中激活了它们。我使用本教程来获取 access_token。我发现了这个问题,所以在请求之前我获得了新的 request_token。
当我第一次请求添加帖子时,我收到了错误:401 "message": "Invalid Credentials", "location": "Authorization"。
当我第二次请求使用新令牌添加帖子时,出现错误:403“消息”:“超出每日限制。请注册”
我的请求代码是:
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", msg[0]);
requestBody.put("content", msg[0] + " " + msg[1]);
final HttpPost request = new HttpPost("https://www.googleapis.com/blogger/v3/blogs/" + mUserID + "/posts");
request.addHeader("Authorization", "Bearer " + mToken);
request.addHeader("Content-Type", "application/json");
request.setEntity(new StringEntity(requestBody.toString()));
final HttpResponse response = mHttpClient.execute(request);
final HttpEntity ent = response.getEntity();
Log.i(SocialPoster.LOG, EntityUtils.toString(ent));
ent.consumeContent();
UPDATE 找到解决方案:只需在请求的 URL 中添加“?key={MY_API_KEY}”即可解决问题