对于我的Android应用程序游戏,我实现了一个允许用户分享游戏结果的按钮.
我已经集成了Facebook SDK,所以我的项目都知道所有类.清单包含以下标记:
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />
<provider android:authorities="com.facebook.app.FacebookContentProvider16..."
android:name="com.facebook.FacebookContentProvider"
android:exported="true"/>
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我可以使用下面的代码分享游戏结果.
public void onShareResult(View view){
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
final ShareDialog shareDialog = new ShareDialog(this);
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Log.d(LOG_TAG, "success");
}
@Override
public void onError(FacebookException error) {
Log.d(LOG_TAG, "error");
}
@Override
public void onCancel() {
Log.d(LOG_TAG, "cancel");
}
});
if (shareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Game Result Highscore")
.setContentDescription("My new highscore is " + sum.getText() + "!!")
.setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=de.ginkoboy.flashcards"))
//.setImageUrl(Uri.parse("android.resource://de.ginkoboy.flashcards/" + R.drawable.logo_flashcards_pro))
.setImageUrl(Uri.parse("http://bagpiper-andy.de/bilder/dudelsack%20app.png"))
.build();
shareDialog.show(linkContent);
}
}
Run Code Online (Sandbox Code Playgroud)
但有一些我不明白的事情.
此外,我在理解Facebook的要求方面遇到了一些麻烦.
这是Facebook显示我的帖子的方式:

这就是我的应用程序似乎发布内容的方式

所以问题是:我的标题和描述在哪里消失了?
最好的祝福
奥利弗
所以,我已经找到了为什么我的标题和描述在Facebook中不可见的原因.
首先感谢@mustafasevgi,但您的解决方案是指SDK 3.5.x,我尝试使用SDK 4.0
回到解决方案......
我发现我已将我的内容网址设置到Google Play商店内的应用程序中.如果您在Google Play商店之外设置了内容网址,则不会覆盖标题和说明.
facebook sdk 3.X 使用此代码。您可以使用 WebDialog。
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.facebook.FacebookException;
import com.facebook.FacebookOperationCanceledException;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.model.GraphUser;
import com.facebook.widget.WebDialog;
import com.facebook.widget.WebDialog.OnCompleteListener;
public class FaceShare extends Activity {
String link = "", id = "", pic = "", title = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
Bundle b = i.getExtras();
// link = b.getString("link");
// id = b.getString("id");
// pic = b.getString("pic");
// title = b.getString("title");
try {
// start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
}
// callback after Graph API response with user object
}).executeAsync();
publishFeedDialog(title, "title", "caption", link, pic);
}
}
// callback when session changes state
});
}
catch (Exception e) {
Log.e("FACE", e.toString());
finish();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
private void publishFeedDialog(String name, String caption, String description, String link, String urlPicture) {
Bundle params = new Bundle();
// params.putString("name", name);
// params.putString("caption", caption);
// params.putString("description", description);
// params.putString("link", link);
// params.putString("picture", urlPicture);
params.putString("name", "name");
params.putString("caption", "caption");
params.putString("description", "description");
params.putString("link", "https://s-media-cache-ak0.pinimg.com/236x/1b/2b/19/1b2b19519b1b3439f783181026d9872b.jpg");
params.putString("picture", "https://s-media-cache-ak0.pinimg.com/236x/1b/2b/19/1b2b19519b1b3439f783181026d9872b.jpg");
Session session = Session.getActiveSession();
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(FaceShare.this, 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) {
Toast.makeText(getApplicationContext(), "Shared.", Toast.LENGTH_LONG).show();
finish();
}
else {
finish();
}
}
else if (error instanceof FacebookOperationCanceledException) {
finish();
}
else {
Toast.makeText(getApplicationContext(),
"error occured, try again",
Toast.LENGTH_LONG).show();
finish();
}
}
})
.build();
feedDialog.show();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13413 次 |
| 最近记录: |