[英]Android Facebook Sdk 4.11.0 How to post a simple status update to wall without any link or image
[英]Android Facebook SDK 3.0 Simple Status Update Without Explicit Login?
我想知道更新用戶Facebook狀態的最簡單方法。 我只想顯示一個“共享”按鈕。 當用戶觸摸“共享”時:
如果他們已經登錄到Facebook,則會出現一個對話框,讓他們選擇在提交給Facebook之前編輯其發布的選項。
如果他們尚未登錄Facebook,將提示您登錄,然后在成功登錄后自動顯示共享對話框。
有沒有一種簡單的方法可以執行此操作,或者我需要實現單獨的Facebook登錄流程?
所以我認為我有一個很干凈的方法。 我歡迎任何評論。
我發布了我的整個Facebook Manager類,該類可以完成登錄以及調出feed對話框的工作:
public class ManagerFacebook
{
private Activity mActivity;
public void updateStatus(final String name, final String caption, final String description, final String link, final String urlPicture,
final Activity activity, final ListenerShareFacebook listenerShareFacebook)
{
mActivity = activity;
// start Facebook Login
Session.openActiveSession(activity, true, new Session.StatusCallback()
{
// callback when session changes state
public void call(final Session session, SessionState state, Exception exception)
{
if (session.isOpened())
{
publishFeedDialog(name, caption, description, link, urlPicture, listenerShareFacebook);
}
}
});
}
private void publishFeedDialog(String name, String caption, String description, String link, String urlPicture,
final ListenerShareFacebook listenerShareFacebook)
{
Bundle params = new Bundle();
params.putString("name", name);
params.putString("caption", caption);
params.putString("description", description);
params.putString("link", link);
params.putString("picture", urlPicture);
Session session = Session.getActiveSession();
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(mActivity, session, params)).setOnCompleteListener(new OnCompleteListener()
{
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)
{
listenerShareFacebook.onShareFacebookSuccess();
}
else
{
// User clicked the Cancel button
listenerShareFacebook.onShareFacebookFailure("Publish cancelled");
}
}
else if (error instanceof FacebookOperationCanceledException)
{
// User clicked the "x" button
listenerShareFacebook.onShareFacebookFailure("Publish cancelled");
}
else
{
// Generic, ex: network error
listenerShareFacebook.onShareFacebookFailure("Error posting story");
}
}
}).build();
feedDialog.show();
}
}
另外,上面引用的是我的Listener界面,因此我可以將與Facebook相關的內容通知我的Activity:
public interface ListenerShareFacebook
{
void onShareFacebookSuccess();
void onShareFacebookFailure(String error);
}
我真的建議這樣做:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Title");
startActivity(Intent.createChooser(sharingIntent, "Share using"));
這不使用facebook sdk,但是使用facebook app。 在我看來,擁有智能手機和Facebook的大多數人都使用此應用程序,並希望通過此應用程序共享所有內容。 用戶也可以點擊分享其他內容(Twitter,短信,G +,電子郵件等)
對我而言,任何Facebook SDK的最佳替代品。 (您也可以附加圖片)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.