Android:如何自动在Facebook墙上发布更新?
-
11-10-2019 - |
题
我希望我的Android应用程序在用户单击按钮时自动发布预设消息。预设消息将由用户设置,因此我猜这并不违反Facebook政策。我该怎么做呢?
其他提示
private static final String[] PERMISSIONS =
new String[] {"publish_stream", "read_stream", "offline_access"};
Facebook authenticatedFacebook = new Facebook(APP_ID);
postButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
authenticatedFacebook.authorize(Tests.this, PERMISSIONS,
new TestPostListener());
}
});
public class TestPostListener implements DialogListener {
public void onComplete(Bundle values) {
try {
Log.d("Tests", "Testing request for 'me'");
String response = authenticatedFacebook.request("me");
JSONObject obj = Util.parseJson(response);
Log.d("Tests", "Testing graph API wall post");
Bundle parameters = new Bundle();
parameters.putString("message", "Amit Siddhpura");
parameters.putString("description", "Hi Mr. Amit Siddhpura");
response = authenticatedFacebook.request("me/feed", parameters,
"POST");
Log.d("Tests", "got response: " + response);
} catch (Throwable e) {
e.printStackTrace();
}
}
public void onCancel() {
}
public void onError(DialogError e) {
e.printStackTrace();
}
public void onFacebookError(FacebookError e) {
e.printStackTrace();
}
}
您必须在Facebook上创建应用程序
并从用户获得身份验证,然后您可以获取Access_Token通过Graph API发布一些消息
我认为您的申请必须请求扩展权限:prubly_stream,offline_access
GitHub上有Facebook Android-SDK源代码,您可以引用它。
不隶属于 StackOverflow