我可以在我的简单Java应用程序中直接调用G + API方法访问我的G +配置文件中的公共数据,而不会绕过" Google引擎" ?那就是使用谷歌API作为我的应用程序中的任何其他jar?
程序是这样的:
import java.io.IOException;
import java.io.Writer;
import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.plus.Plus;
import com.google.api.services.plus.PlusRequestInitializer;
import com.google.api.services.plus.model.Activity;
import com.google.api.services.plus.model.ActivityFeed;
import com.google.api.services.plus.Plus.Builder;
import java.util.List;
public class Main {
private static final String API_KEY = "dfhsdgdgdfhd";
private static final long serialVersionUID = 1;
public static void main( String[] args ){
HttpTransport httpTransport = new UrlFetchTransport();
JsonFactory jsonFactory = new JacksonFactory();
Plus plus = new Plus.Builder(httpTransport, jsonFactory,
null).setApplicationName("TestGoogleApi")
.setGoogleClientRequestInitializer(new
PlusRequestInitializer(API_KEY))
.build();
ActivityFeed myActivityfeed;
myActivityfeed = plus.activities().search("Google").execute();
List<Activity> myActivities = myActivityfeed.getItems();
for (Activity a : myActivities) {
System.out.println(a.getTitle());
}
}
}