これはStackOverflowに関する私の最初の質問ですので、私が無視したことがある場合は教えてください!Blogger APIサンプルコード
私が行っているいくつかの言語分析研究のために、Bloggerの公開ブログからブログ投稿データを取得しようとしています。 Java APIはかなり簡単ですが、LocalServerReceiver()からOAuthorizationに必要なすべての依存関係まで多くの依存関係がないため、https://developers.google.com/blogger/docs/3.0/reference/posts/list#examplesのGoogleのコードサンプルは機能しません。 APIエクスプローラはうまく動作しますが、明らかに私自身のコードには何かが必要です。
私は他のStackOverflow質問からのコードフラグメントを利用しようとしましたが、それは私のものと似ていましたが、依然として依存関係の問題に直面しています。
ここで原因コードの廃止のいくつかの並べ替えに私の問題を解決していない私が見てきた質問のいくつかのリストです:
Why does Java not allow me to use OAuth2Native methods here?
- Authenticate own Google account for Blogger API with Java
私はOAuthPlaygroundを使用して認証コードを取得し、Proper Form of API request to Blogger using Java/App Engine -error 401のiamkhovaのソリューションの機能の一部を複製しようとしています。私が実際にアクセスしているブログには何も書き込もうとしていないことに注意してください。私はちょうど分析のためのポストデータを得ることができるようにしたい。
現在、私はロガーを取り出し、Googleのサンプルコードから必要なものを複製するgetPosts()関数を追加するだけで、iamkhovaのソリューションを変更しました。
public class BlogHandler
{
static final String API_KEY = {My API Key};
public Blogger blogger = null;
public Blog blog;
public java.util.List<Post> posts;
public BlogHandler() {}
public void executeGetBlogByUrl (String url) throws IOException {
GetByUrl request = blogger.blogs().getByUrl(url);
this.blog = request.setKey(API_KEY).execute();
}
public void getPosts() throws IOException
{
List postsListAction = blogger.posts().list(this.blog.getId());
// Restrict the result content to just the data we need.
postsListAction.setFields("items(author/displayName,content,published,title,url),nextPageToken");
// This step sends the request to the server.
PostList posts = postsListAction.execute();
// Now we can navigate the response.
int postCount = 0;
int pageCount = 0;
while (posts.getItems() != null && !posts.getItems().isEmpty()) {
for (Post post : posts.getItems()) {
System.out.println("Post #"+ ++postCount);
System.out.println("\tTitle: "+post.getTitle());
System.out.println("\tAuthor: "+post.getAuthor().getDisplayName());
System.out.println("\tPublished: "+post.getPublished());
System.out.println("\tURL: "+post.getUrl());
System.out.println("\tContent: "+post.getContent());
}
// Pagination logic
String pageToken = posts.getNextPageToken();
if (pageToken == null || ++pageCount >= 5) {
break;
}
System.out.println("-- Next page of posts");
postsListAction.setPageToken(pageToken);
posts = postsListAction.execute();
}
}
public void setupService() throws IOException {
AppIdentityCredential credential = null;
credential = new AppIdentityCredential(Arrays.asList(BloggerScopes.BLOGGER)); // Add your scopes here
this.blogger = new Blogger.Builder(new UrlFetchTransport(), new JacksonFactory(), credential).setApplicationName("chsBlogResearch").build();
}
}
現在、私は次のエラーを持っている:MemcacheServiceImplとAppIdentityServiceImplでエラーの両方のためのコード行をクリック
Exception in thread "main" com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'memcache' or call 'Get()' was not found.
at com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:173)
at com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:171)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:89)
at com.google.appengine.api.memcache.MemcacheServiceImpl.quietGet(MemcacheServiceImpl.java:26)
at com.google.appengine.api.memcache.MemcacheServiceImpl.get(MemcacheServiceImpl.java:49)
at com.google.appengine.api.appidentity.AppIdentityServiceImpl.getAccessToken(AppIdentityServiceImpl.java:286)
at com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential.intercept(AppIdentityCredential.java:98)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at BloggerData.BlogHandler.executeGetBlogByUrl(BlogHandler.java:29)
は、その時点でのコードのない行が存在しないことを教えてください。依存関係のためにEclipse内でMavenを使用しています。
このコードで私が本当にわからないのはスコープのアイデアだけですが、それが私のエラーの原因になっているとは思いません。
この投稿データを取得するのは、思ったよりも時間がかかりました。
更新:getting strange exception trying to implement asynchronous http in google app engine for java上記のエラーに関するもう少し詳しい情報が提供されました。どうやら、このApiProxy jarはコンソールアプリケーションから呼び出すことはできません。
あなたは何をURLとしてexecuteGetBlogByUrl()メソッドに渡していますか? – ManoDestra
現在のところ、ランダムなブログのURLの文字列(私のものではなく、テスト目的のもの)です。私は、ブログが実際にBloggerのブログであることを最初に確認しました。 – tatertot
ManoDestraはあなたの質問に基づいて、より良いテスト用のURL(実際に私のものです)を試してみることにしました - ここにブログがあります:https://chstesting.blogspot.com/ – tatertot