Java 以编程方式获取Google+;状态更新
有没有一种方法可以通过编程获取用户档案的Google+更新?在获取状态的文档中,我似乎找不到太多关于获取状态的内容。我想通过发出HTTP请求来获取数据,或者如果Android上有某种SDK可以帮助我,那就可以了。以下代码将有助于检索HTTP响应Java 以编程方式获取Google+;状态更新,java,android,google-plus,Java,Android,Google Plus,有没有一种方法可以通过编程获取用户档案的Google+更新?在获取状态的文档中,我似乎找不到太多关于获取状态的内容。我想通过发出HTTP请求来获取数据,或者如果Android上有某种SDK可以帮助我,那就可以了。以下代码将有助于检索HTTP响应 import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Type; import java.net.HttpURLConnection; impor
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
import java.util.zip.GZIPInputStream;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
public class GooglePlusStatusHelper {
public GooglePlusStatusHelper() {
}
public static void main(String... args) {
GooglePlusStatusHelper googlePlusStatusHelper = new GooglePlusStatusHelper();
try {
googlePlusStatusHelper.tagsUsed();
} catch (IOException e) {
e.printStackTrace();
}
}
private void tagsUsed() throws IOException {
URL url = createQuery("users");
Type dataType = new TypeToken<Wrapper<Status>>(){}.getType();
Status status = executeQuery(url, dataType);
System.out.println(status);
}
private URL createQuery(String inputParam) throws MalformedURLException {
String baseUrl = "http://api.example.com/" + inputParam ;
System.out.println(baseUrl);
URL url = new URL(baseUrl);
return url;
}
private Status executeQuery(URL url, Type clz) throws IOException {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
System.out.println("Response Code:" + conn.getResponseCode());
System.out.println("Response Message:" + conn.getResponseMessage());
System.out.println("TYPE:" + conn.getContentType());
InputStream content = conn.getInputStream();
String encoding = conn.getContentEncoding();
if (encoding != null && encoding.equals("gzip")) {
content = new GZIPInputStream(content);
}
String result = new Scanner(content, "UTF-8").useDelimiter("\\A").next();
content.close();
Gson gson = new Gson();
return gson.fromJson(result, clz);
}
}
您正在寻找的API是。这将列出Google+相当于Facebook的状态更新。引用的页面具有示例代码,可以帮助您开始
访问API时,您应该。谢谢您的回复!网上有任何官方文件可以做这件事吗?谢谢!正是我要找的!
public class Status {
private int count;
private String status;
......
public String toString() {
String result = "\ncount: " + count +
"\status:" + status;
result = result + "\n------------";
return result;
}
}