Facebook: 使用Java API发布内容

Categories: Java; Tagged with: ; @ December 4th, 2010 12:39

需求: 通过Java端直接发布内容到Facebook Wall.

使用的API:
http://code.google.com/p/facebook-java-api/ 该API需要依附于HttpClient3, Json.  源自官方Java api.

Java端发布代码:

	/**
	 * update Facebook wall.
	 * @param infiniteSessionKey
	 * @param mesg
	 * @return
	 */
	public boolean publishMesg(String infiniteSessionKey, String mesg) {
		try {
			FacebookJsonRestClient facebook = new FacebookJsonRestClient(API_KEY, SECRET_KEY, infiniteSessionKey);
			FacebookJsonRestClient facebookClient = (FacebookJsonRestClient)facebook;
			facebookClient.stream_publish(mesg, null, null, null, null);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

对于普通用户:

1.  安装并授权程序

2. 获得infiniteSessionKey, Java端将使用infiniteSessionKey随时访问更新Facebook.

主要参考: http://blog.theunical.com/facebook-integration/facebook-java-api-example-to-publish-on-wall/

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.