2014-01-06 64 views
0

我正在使用Google + HTTP APIpeople/get端点发出很多请求。事实证明这很慢,因为它需要为每个用户ID提供一个HTTP请求。

在文档中没有提到它,但是有什么方法可以在Google Plus API上发出批量请求吗?

或者,对于此用例的任何优化提示都非常受欢迎。Google Plus API上的批量请求

+0

从谷歌显影剂导向https://developers.google.com/gdata/docs/batch – StarsSky

+0

Google+尚未包括在谷歌数据API:https://开头developers.google.com/gdata/docs/directory – LoicAG

+1

这是相同的批处理语义AFAIK。如果您使用的是Java客户端库,则批处理支持良好,与Python相同。 –

回答

1

我设法通过Google APIs Java client library在Google+ API上提出批量请求。

下面是一个代码示例:

BatchRequest batch = plus.batch(); 

Get me = plus.people().get("me"); 
Get angularJS = plus.people().get("110323587230527980117"); 

BatchCallback<Person, GoogleJsonErrorContainer> cb = new BatchCallback<Person, GoogleJsonErrorContainer>() { 
    @Override 
    public void onSuccess(Person person, HttpHeaders responseHeaders) 
     throws IOException { 
    System.out.println("batch success"); 
    System.out.println(person.getDisplayName()); 
    } 

    @Override 
    public void onFailure(GoogleJsonErrorContainer e, HttpHeaders responseHeaders) 
     throws IOException { 
    System.out.println("batch failure"); 
    } 
}; 

batch.queue(me.buildHttpRequest(), Person.class, GoogleJsonErrorContainer.class, cb); 
batch.queue(angularJS.buildHttpRequest(), Person.class, GoogleJsonErrorContainer.class, cb); 

batch.execute();