gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:54:34 25 4
gpt4 key购买 nike

我找不到很多 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com