我想向我选择的Facebook好友发送通知,根据该文档,我使用了以下代码。
private void sendNotification() {
Bundle params = new Bundle();
params.putString("href", "/testurl?param1=value1");
params.putString("template", "This is a test message");
/* make the API call */
new Request(Session.getActiveSession(), "/me/notifications", params,
HttpMethod.POST, new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
Log.d(LOG_TAG, response.toString());
}
}).executeAsync();
}
我尝试了很多,发现facebook已经禁止在朋友墙上发帖,所以我可以选择发送通知,告知自己与所选朋友的活动。 这段代码对我不起作用。如果有人有解决方案请分享。我会非常感谢。谢谢
答案 0 :(得分:0)
根据documentation -
目前,只有Facebook.com上的应用才能使用应用通知。通知仅显示在Facebook.com的桌面版本上。
因此,您必须在Facebook内部使用画布应用程序发送通知。
另外,还有其他不同的分享方式,请看一下这篇文章:Sharing in Android
修改强>
实施/feed
API -
private void publishStory() {
Session session = Session.getActiveSession();
if (session != null){
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle postParams = new Bundle();
postParams.putString("name", "Facebook SDK for Android");
postParams.putString("caption", "Build great social apps and get more installs.");
postParams.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
postParams.putString("link", "https://developers.facebook.com/android");
postParams.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
Request.Callback callback= new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id");
} catch (JSONException e) {
Log.i(TAG,
"JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(getActivity()
.getApplicationContext(),
error.getErrorMessage(),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity()
.getApplicationContext(),
postId,
Toast.LENGTH_LONG).show();
}
}
};
Request request = new Request(session, "me/feed", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}