xml Google - 服务帐户使用情况(例如:从Blogger网站上读取)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml Google - 服务帐户使用情况(例如:从Blogger网站上读取)相关的知识,希望对你有一定的参考价值。
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.blogger.Blogger;
import com.google.api.services.blogger.BloggerScopes;
import com.google.api.services.blogger.model.Blog;
import com.google.api.services.blogger.model.Post;
import com.google.api.services.blogger.model.PostList;
import java.io.FileInputStream;
import java.util.Collections;
public class BloggerReadPostList {
public static void main(String[] args) throws Exception {
final String BLOG_URL = "http://attivissimo.blogspot.com";
final String CRED_FILE_PATH = System.getProperty("user.home") + "/credentials.json";
final String APPLICATION_NAME = "SampleBloggerReading";
final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
final JsonFactory JSON_FACTORY = new JacksonFactory();
// Specify "Authorization Scope" [BloggerScopes.BLOGGER = "https://www.googleapis.com/auth/blogger"]
GoogleCredential credential = GoogleCredential
.fromStream(new FileInputStream(CRED_FILE_PATH))
.createScoped(Collections.singleton(BloggerScopes.BLOGGER));
Blogger blogger = new Blogger.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME).build();
String blogId = blogger.blogs().getByUrl(BLOG_URL).execute().getId();
// Start from first page
Blogger.Posts.List action = blogger.posts().list(blogId).setPageToken(null);
// Restrict the result content to just the data we need.
action.setFields("items(author/displayName,id,content,published,title,url),nextPageToken");
action.setMaxResults(10L);
// This step sends the request to the server.
PostList list = action.execute();
for (Post post: list.getItems()) System.out.println("[" + post.getId() + "] " + post.getTitle());
System.out.println("Next token = " + list.getNextPageToken());
}
}
{
"type": "service_account",
"project_id": "...",
"private_key_id": "...",
"private_key": "...",
"client_email": "...",
"client_id": "...",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "..."
}
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-blogger</artifactId>
<version>v3-rev61-1.25.0</version>
</dependency>
以上是关于xml Google - 服务帐户使用情况(例如:从Blogger网站上读取)的主要内容,如果未能解决你的问题,请参考以下文章
使用 JS 的服务帐户调用 Google bigquery
在没有 OAuth 的情况下为自己的帐户使用 Google API
在不设置 SRV 记录的情况下连接到 Google 帐户
如何通过 Google Drive .NET API v3 使用服务帐户访问 Team Drive
使用 REST API 向 Google Cloud Platform 上的服务帐户添加角色
如何使用API Explorer作为服务帐户?