使用Java博客API v3动态发布博客 [英] Using Java blogger API v3 to post on blog dynamically

查看:119
本文介绍了使用Java博客API v3动态发布博客的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个关于使用Java博客API v3将帖子动态发布到我的博客账户的问题。 第一个

我使用以下代码获取访问我的博客的凭证:

  GoogleCredential凭证=新的GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(emailAddress)
.setServiceAccountPrivateKeyFromP12File(
新文件(p12FileLocation))
.setServiceAccountScopes( Collections.singleton(BloggerScopes.BLOGGER))
.build();

credential.setAccessToken(zRLqmkM82626Uym9Uv1Jsdd);

$ b Blogger Blogger = new Blogger.Builder(httpTransport,JSON_FACTORY,凭证)
.setApplicationName(Blogger)
.build();
// ....剩下的代码准备发布并发送它......

我设置了以下谷歌页面生成的访问令牌(credential.setAccessToken): https: //developers.google.com/oauthplayground



但是此令牌每3600秒过期一次。所以我再次访问该页面并按下刷新访问令牌来获取另一个并在上面的代码中再次使用它。



这是否是正确的方法访问我的博客并以编程方式动态发布内容和文章?

控制台 https://developers.google.com/console 我看到我每天有10000个请求和一个限制1次请求/秒/用户



在使用我的上述代码动态使用大约50个帖子(请注意,我在连续请求之间等待了大约5秒钟),我开始从api调用接收到以下错误:

 <$ c $ {
code:403,
errors:[{
domain:usageLimits,
message:Rate Limit Exceeded,
原因:rateLimitExceeded
}],
消息:费率Limi t超出

我回到我的配额页面,我发送没有从我每天允许的请求中减少!!!



有些我的第二个问题是:

我是否忘记了一个特定的配置以正确地操作我的博客?
$ b

感谢您的帮助和支持。 b $ b

解决方案

没有办法为Blogger预先授权某人,所以我相信访问Blogger Api的唯一方法是通过Auth 2 Playground生成访问令牌,然后使用令牌进行API调用。



尽管它在控制台上显示10000个请求/天并且限制为1个请求/秒/用户,但实际上只是Blogger api默认情况下每天最多允许50个请求。直到有一段时间,有规定要求额外的配额,指定现在已经停止使用的配额。

I have two issues regarding using Java blogger API v3 to dynamically posting posts to my blogger account.

First

I used the following code to get credential for accessing my blog:

GoogleCredential credential = new GoogleCredential.Builder()
                .setTransport(httpTransport)                
                .setJsonFactory(JSON_FACTORY)
                .setServiceAccountId(emailAddress)
                .setServiceAccountPrivateKeyFromP12File(
                new File(p12FileLocation))
                .setServiceAccountScopes(Collections.singleton(BloggerScopes.BLOGGER))
                .build();

        credential.setAccessToken("zRLqmkM82626Uym9Uv1Jsdd");


        Blogger blogger = new Blogger.Builder(httpTransport, JSON_FACTORY, credential)
                .setApplicationName("Blogger")
                .build();
        // .... rest of the code to prepare post and send it ......

I set the access token above (credential.setAccessToken) that was generated from the following google page: https://developers.google.com/oauthplayground

but this token is expired every 3600 seconds. so I visit the page again and press the button "Refresh access token" to get another one and use it again in above code.

Is this the correct method of accessing my blog and dynamically posting contents and articles programmatically?

Second

In google developers console https://developers.google.com/console i saw that I have 10000 requests/day and a limit of 1 request/second/user

BUT

after correctly posting dynamically using my above code around 50 posts (note that I set a wait for around 5 seconds between a consecutive requests), I started receiving the following error from the api call:

{
  "code" : 403,
  "errors" : [ {
    "domain" : "usageLimits",
    "message" : "Rate Limit Exceeded",
    "reason" : "rateLimitExceeded"
  } ],
  "message" : "Rate Limit Exceeded"
}

I return to my quota page and I see that the requests that I send did not decreased from my allowed requests per day !!!

Some my second question is:

Does I forget a specific configuration for correctly manipulate my blog dynamically ?

Thank you in advance for your help and support.

解决方案

There is no way to preauthorize someone for Blogger so I believe the only way to access Blogger Api is to generate access token through Auth 2 Playground and then using the token for API call.

Even though it shows 10000 requests/day and a limit of 1 request/second/user on the console, the fact is Blogger api only permit maximum 50 requests per day by default. Till a while back there was provision to request additional quota by specifying genuine need for it which has now been discontinued.

这篇关于使用Java博客API v3动态发布博客的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆