Google api Google Blogger API-未经授权的用户没有创建新帖子的权限

Google api Google Blogger API-未经授权的用户没有创建新帖子的权限,google-api,blogger,google-api-java-client,Google Api,Blogger,Google Api Java Client,使用Google Blogger API插入新帖子时出现以下错误 com.google.gdata.client.GoogleService$SessionExpiredException: Unauthorized User does not have permission to create new post at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.j

使用Google Blogger API插入新帖子时出现以下错误

com.google.gdata.client.GoogleService$SessionExpiredException: Unauthorized
User does not have permission to create new post

at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:570)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
  • 使用服务帐户、OAuth2和GoogleCredential生成 accessToken
  • accessToekn已成功创建
  • 我在某个地方读到谷歌不支持服务账户 博客API
  • 因此,尝试使用客户机Id和客户机机密来获取可以 再次用于使用作用域获取访问令牌
    "".
  • 在这样做的时候,我得到了一个错误,说“不是一个有效的作用域”
获取访问令牌然后进行post调用以插入新post的正确且有效的方法是什么?如果Blogger不允许Blogger API的服务帐户,并且我需要在获取访问令牌之前对请求进行身份验证,这对我也适用。我只需要一个机制来为BloggerAPI生成一个有效的访问令牌,稍后允许我插入一篇文章

目前我的代码如下所示。谢谢你在这方面的帮助。谢谢

     String clientId = "xxxx.apps.googleusercontent.com";
        String emailAddress = "xxxxx@developer.gserviceaccount.com";
        JsonFactory JSON_FACTORY = new JacksonFactory();
        HttpTransport httpTransport = null;
        try {
            httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        }

 catch (GeneralSecurityException e1) {
        e1.printStackTrace();
    }

File file = new File("C://xxxx/IQ/PostBlogPost-d6158daa91a5.p12");

GoogleCredential credential = null;

try {
    credential = new GoogleCredential.Builder()
            .setTransport(httpTransport)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(emailAddress)
            .setServiceAccountPrivateKeyFromP12File(file)
.setServiceAccountScopes(Collections.singleton("https://www.googleapis.com/auth/blogger")).build();
        } catch(Exception ex){

        }

credential.refreshToken();

BloggerService myService = new BloggerService("exampleCo-exampleApp-1");
        myService.setAuthSubToken(credential.getAccessToken());
        myService.setOAuth2Credentials(credential);


try {
 Entry myEntry = new Entry();
 myEntry.setTitle(new PlainTextConstruct("test-title"));
 myEntry.setContent(new PlainTextConstruct("xxxxxxx"));

 // Ask the service to insert the new entry
 URL postUrl = new URL("http://www.blogger.com/feeds/" + "xxxx" + "/posts/default");
  myService.insert(postUrl, myEntry);
 } catch (ServiceException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
 }

由于服务帐户需要预授权,并且在没有Blogger批准电子邮件的情况下,无法为Blogger预授权。Blogger API不支持服务帐户,您需要使用OAuth2Tanks@dalmto。是的,我现在正在尝试使用通过Oauth 2游乐场生成的访问令牌并发出Post请求。那对我也会有用的。