Android Facebook API和ShareLinkContent [英] Android Facebook API and ShareLinkContent

查看:792
本文介绍了Android Facebook API和ShareLinkContent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的Android应用程序游戏我已经实现了一个按钮,允许用户分享一个游戏的结果。



我已经整合了Facebook SDK,所以所有的类是我的项目已知。
清单包含以下标签:

 < meta-data android:name =com.facebook.sdk .ApplicationId
android:value =@ string / app_id/>

< provider android:authority =com.facebook.app.FacebookContentProvider16 ...
android:name =com.facebook.FacebookContentProvider
android:exported = 真/>

当我运行应用程序时,我可以使用下面的代码分享游戏的结果。 >

  public void onShareResult(查看视图){
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,
}

@Override
public void onCancel(){
Log.d(LOG_TAG,cancel);
}
});


if(shareDialog.canShow(ShareLinkContent.class)){

ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle(Game结果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);
}


}

但是有一些我不明白的东西。




  • 在发布之前,共享链接与对话框中看到的不同。

  • 图片似乎已通过互联网提供。即不可能从我的项目中设置资源的图像。



此外,我对Facebook所要求的一切有所了解。



这是Facebook显示我的发布方式:





这就是我的应用程序似乎发布内容p>



所以问题是:我的标题和描述在哪里?



最好的问候



Oliver

解决方案

所以,我发现了我的标题和描述在Facebook上不可见的原因。



首先感谢@mustafasevgi,但是您的解决方案是指SDK 3.5.x,我试图使用SDK 4.0



回到解决方案...



我发现我已经在Google Play商店内设置了我的内容Url到我的应用程序。如果您在Google Play商店之外设置了内容网址,标题和说明将不会被覆盖。


for my Android App Game I have implemented a Button that allows the user to share the result of a game.

I have integrated the Facebook SDK, so all classes are known to my project. The manifest contains the following tags:

<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"/>

When I run the app I can share the result of the game with the code below.

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);
    }


}

However there are some things I do not understand.

  • The shared link looks different from what I see in the dialog before I post.
  • Images seem to have been available via internet. i.e. It is not possible to set an image of a resource from my project.

Furthermore I have some trouble understanding what Facebook is requiring.

This is how Facebook displays my posting:

And this is how my App seem to post the content

So the question is: Where is my title and description gone???

Best regards

Oliver

解决方案

So, I have found out the reason why my title and description was not visible in facebook.

First of all thanks @mustafasevgi but your solution refers to SDK 3.5.x where I tried to use SDK 4.0

Coming back to the solution...

I have found out that I have set up my content Url to my App inside the Google Play Store. If you set up a content Url outside of Google Play Store the title and description will not be overwritten.

这篇关于Android Facebook API和ShareLinkContent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆