android - 我如何使用其 Android SDK 简单地在 Facebook 墙上分享内容?

标签 android facebook facebook-graph-api facebook-android-sdk facebook-wall

我找不到很多 FB + Android SDK 的示例,而且示例不够简单(其中一些已弃用)。我的简单目标是使用我的 Android 应用程序在 FB 上分享一些内容。当我开发 iOS 应用程序时,它很简单

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate facebookLogin];


NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"pikSpeak", @"name",
                               shareURL, @"link",
                               @"pikSpeak for iPhone !", @"caption",
                               @"Record audio at the moment of the image taken using pikSpeak and feel the moment come alive", @"description",
                               @"shared an audible pic using pikSpeak cam", @"message",
                               imageURL,@"picture",
                               nil];

[[appDelegate facebook] requestWithGraphPath:@"feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

此代码处理 session 并在应用重启时保存 session 详细信息。

1) 如何在 Android 中简单地分享一些东西。

2) 我看到 Facebook(String app_id) 已弃用。如果是这样,那么它的替代品是什么?

附言: 使用 Facebook 3.0 SDK

最佳答案

取自Share on User's Wall using Facebook SDK :

private void share() {
    Bundle bundle = new Bundle();
    bundle.putString("caption", "Harlem Shake Launcher for Android");
    bundle.putString("description", "Your android can do the Harlem Shake. Download it from google play");
    bundle.putString("link", "https://play.google.com/store/apps/details?id=mobi.shush.harlemlauncher");
    bundle.putString("name", "Harlem Shake Launcher");
    bundle.putString("picture", "http://shush.mobi/bla.png");
    new WebDialog.FeedDialogBuilder(mContext, mySession, bundle).build().show();
}

如果您需要登录(将此添加到您需要登录/共享的 Activity 中):

Session.openActiveSession(this, true, new Session.StatusCallback() {

    @Override
    public void call(Session session, SessionState state, Exception exception) {
        if(session.isOpened()) {
            share();
        }
    }
});

您需要添加到您的 Activity 中:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode) {
    default:
        if(Session.getActiveSession() != null) //I need to check if this null just to sleep peacefully at night
            Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
        break;
    }
}

关于android - 我如何使用其 Android SDK 简单地在 Facebook 墙上分享内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15715179/

相关文章:

android - 从 Facebook 获取电子邮件 - FB android SDK

android - UnsatisfiedLinkError AudioRecordNew

Facebook 登录按钮消失了

ios - Facebook 分享 iOS Swift

facebook - 填充 facebook 提要对话框消息框

facebook - 有没有办法在 Facebook 中获取消息线程的 ID?

php - 通过 PHP SDK 以用户身份发布到 Facebook 粉丝页面提要

Android Room,如何保存一个实体,其中一个变量是密封的类对象

java - 在微调器中显示 TTS 可用语言

android - 更改 org.gradle.jvmargs 的值可修复 "This problem might be caused by incorrect configuration of the daemon."错误