0
我遇到如下代碼: -自動發佈到Facebook牆
public void publishFeedDialog(final Activity activity, final FacebookLogin fl)
{
Session session = Session.getActiveSession();
//if session is not empty and it is opened
if (session != null && session.isOpened()){
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(activity, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle params = new Bundle();
params.putString("name", "test");
params.putString("message", "MESSAGE TO GO WITH THE IMAGE");
params.putString("description", "test test test");
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(activity,
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("POST")
.setMessage("")
.setCancelable(false)
.setNegativeButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
// User clicked the Cancel button
Toast.makeText(activity,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(activity,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(activity,
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}
else
{
// login with facebook if no session is available
}
}
我試圖讓短信/描述Facebook發佈,但是失敗了。而且我也有問題自動分享。目前我需要點擊發布按鈕纔可以發佈內容到我的臉書。任何幫助將升值。
謝謝先進。