2014-12-05 134 views
8

我试图在Facebook上分享一些内容,但我有很多问题。 我已经添加了正确的keyhash,并在Facebook上创建了该应用并将其生效。 当我试着分享一些似乎很好,你可以看到:Facebook的shareDialog不显示任何内容

enter image description here

但我点击后后已经是空的: enter image description here

这是一个权限问题?我读过很多关于这个堆栈,但我找不到工作... 这是代码的答案:

public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) 
     { 
      case R.id.action_share:   
       Intent intent2=new Intent(Intent.ACTION_SEND); 
       intent2.setType("text/plain"); 
       intent2.putExtra(Intent.EXTRA_TEXT,"'"+ random + "'" + "\n"+"By Random Quotes"); 
       startActivity(Intent.createChooser(intent2, "Share via")); 
       break; 

       case R.id.randombut: 
        Frasi(); 

       case android.R.id.home: 
        Intent homeIntent = new Intent(this, MainActivity.class); 
        homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
        startActivity(homeIntent); 
       break; 

       case R.id.facebook: 
        FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this) 
        .setApplicationName("Random Quotes") 
        .setDescription(random) 
       .setPicture("https://lh6.ggpht.com/1UJ89ho9pvVLPYS6NsFVQdb7KoQPALMhkw1w7DnNDqcfDYJ-tRxruaf2YLMLyqhnG_g=w300-rw") 
        .setLink("https://play.google.com/store/apps/details?id=com.techappstudios.randomquotes") 
        .build(); 
        uiHelper.trackPendingDialogCall(shareDialog.present()); 

     } 
     return true; 
    } 
+3

我开始一个赏金,因为我很感兴趣太 – 2014-12-08 09:39:36

回答

0

我觉得这涉及到权限,则需要请求publish_actions许可。 facebook第一次会要求接受新的许可。一旦你接受了,sharedialog将直接显示。

这就是我所做的,但代码我用您的共享信息取代。

final Session activteSession = Session.getActiveSession(); 
     if(!activteSession.isPermissionGranted("publish_actions")) { 
      Session.getActiveSession().requestNewPublishPermissions(new Session.NewPermissionsRequest(this, "publish_actions")); 
     } 
     FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this) 
       .setApplicationName("Random Quotes") 
       .setDescription(random) 
      .setPicture("https://lh6.ggpht.com/1UJ89ho9pvVLPYS6NsFVQdb7KoQPALMhkw1w7DnNDqcfDYJ-tRxruaf2YLMLyqhnG_g=w300-rw") 
       .setLink("https://play.google.com/store/apps/details?id=com.techappstudios.randomquotes") 
       .build(); 
       uiHelper.trackPendingDialogCall(shareDialog.present()); 
     mFacebookUIHelper.trackPendingDialogCall(shareDialog.present()); 

希望这会有所帮助。

+0

它给了我一个错误,因为我已经在清单申报com.facebook.LoginActivity,和我已修复它,但现在它给了我这个错误: java.lang.UnsupportedOperationException:会话:试图请求新的权限,当前未打开的会话。 – 2014-12-10 19:52:35

1

我有类似的问题。

我通过改变图片的来源来修复它(不要问我这是为什么,因为我真的不知道)。

我没有从Facebook或谷歌等网站抓取我的图片网址,而是将图片上传到gethub。通过gethub,图片网址以.png结尾。图片,链接和描述都是按照他们应该发布的内容发布的。

试试看。我希望它有帮助。

+0

只是我删除了图像,它的工作,但我不知道如何添加图像。 – Rahul 2016-05-23 09:05:50

0

从Facebook SDK的最新更新中,Facebook不允许预先填写文本。所以你现在只能分享网址。这不是你使用ShareDialog或Share Intent的问题。

请参考下面的错误链接查看更多细节

https://developers.facebook.com/bugs/332619626816423

+0

这是一个关于intent metod的错误,但我使用共享对话框,所以我认为它是不同的。其他应用程序正在这样做 – 2014-12-15 08:53:13

+0

我认为所有方法的错误。即使sharer.php现在也不工作。你可以看到这个链接https://www.facebook.com/sharer/sharer.php?u=http://www.google.com&t = hello – 2014-12-16 07:22:29

+0

现在预填充内容是不允许的任何类型的共享方法。你可以看到Facebook政策分享内容https://developers.facebook.com/policy/#control – 2014-12-16 07:31:17