Search Unity

Facebook FB.ShareFeed not posting image linked

Discussion in 'Scripting' started by carking1996, Jul 27, 2017.

  1. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,563
    Hello, I'm trying to post to facebook, and all goes great. But when I use the FB.FeedShare and try to share a picture, even if I use FB's 'debugger' to get the image first and cache it, even if I already share it a couple of times, it's not showing my picture. Anyone ever get this issue? I'm also not getting the captions or descriptions.. Just the picture from the link.

    Code (CSharp):
    1.         FB.FeedShare(
    2.             string.Empty, //toId
    3.             new System.Uri(""), //link
    4.             "BeetleJuice: Bad as Can", //linkName
    5.             "", //linkCaption
    6.             "Get BeetleJuice: Bad as Can for iOS and Android!", //linkDescription
    7.             new System.Uri("http://www.flightsystemsllc.com/beetlejuicefb.png"), //picture
    8.             string.Empty, //mediaSource
    9.             ShareCallback //callback
    10.         );
     
    Gokusansan and ikoukas like this.
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,861
    So, welcome to the wonderful world of Facebook where they change things and forget to really inform us or they don't update their Unity SDK to reflect the changes (or their examples)

    Basically, you can no longer use FeedShare or ShareLink the way it was intended. Instead, I had to create an html file with meta tags that I pass in as the first parameter in the ShareLink call. This meta html file contains all the information that we use to pass in in place of the parameters (note the rest of the sharelink parameters will be null or "").

    It's a pain to deal with. It took a bit but we got the image working and then had to add some redirect code to the html file so that if a user clicks on the shared image it still takes them to the game and not to the html file link. While this may not be how to do it, it's the only way I got it working right.

    This is where they talk about the change https://developers.facebook.com/blog/post/2017/06/27/API-Change-Log-Modifying-Link-Previews/

    And this talks a bit about the meta tag system that you'll use https://developers.facebook.com/docs/sharing/webmasters#markup
     
  3. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,563
    Thanks! I didn't know about that. I'm gonna try it out.
     
  4. daclu_10

    daclu_10

    Joined:
    Jun 18, 2014
    Posts:
    3
    Hi Brathnann, can you please tell how to do this part?
    "then had to add some redirect code to the html file so that if a user clicks on the shared image it still takes them to the game and not to the html file link. "
    since the img its referenced on a meta tag on the head tag, it does not have an "a" tag, right? so how did you set the img to be a button redirecting to the link you've wanted?

    how big, width and height should the imgs be?

    Thanks a lot for your posts.
     
    Last edited: Jan 25, 2018
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,861
    Unfortunately, I didn't design the redirect on our website itself. In the html file with the meta tags (which are in the head part of the html) I just added

    Code (CSharp):
    1. <body>
    2. <script>
    3.   window.location.assign("websiteLink here");
    4. </script>
    5. </body>
    The website link is a link to our gamewebsite which then handles which platform they are on and redirects to the clicker to FB or one of the mobile stores. But our web person created that.

    I can't say this is the best solution though. Just what I did to address the issue.
     
  6. daclu_10

    daclu_10

    Joined:
    Jun 18, 2014
    Posts:
    3
    Hi again, thanks a lot for your quick reply.
    Well i do have a gamewebsite, i've created a different html for these sharing pourposes, in which i have added the meta tags on the head part, and now the script you just wrote on the body part (writing my gamewebsite link where you've indicated)...still when i click the image it send me to the html with the meta tags, not the gamewebsite .

    I ask for the img size because im getting blurry results, it may be caused by the web images retina display issue, but no idea how to fix it in these particular case.
     
  7. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,861
    The feedshare call takes a link, this is where you pass in the link to the html file. This html file contains your metatags and the code I shared above for the body tags. Then when a user clicks the link, it goes to that html file which then redirects them to the link that you assign in the body tags.

    Our share images are 1200x627 which I think was one of the sizes facebook recommends.
     
  8. daclu_10

    daclu_10

    Joined:
    Jun 18, 2014
    Posts:
    3
    Hi Brathnann, i want to thank you, you were really helpfull.
    i did have a little more struggle thought, "window.location.assign" for whatever reason did not worked, but "window.location.href" did just fine. I' ve founded this method on:
    https://appendto.com/2016/04/javascript-redirect-how-to-redirect-a-web-page-with-javascript/

    Thanks again.

    Oh one last question, as the info that appear on the share dialog is submited direcly on the html file, is there a way to use data stored on my c# variables? for example, scores?
     
  9. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,861
    Yeah, there were a few different methods that I found for the redirect. assign worked for what I did, so I went with it.

    Glad you found something that worked for you! :)
     
  10. Amirraza

    Amirraza

    Joined:
    Jul 13, 2018
    Posts:
    17
  11. Amirraza

    Amirraza

    Joined:
    Jul 13, 2018
    Posts:
    17
    @Brathnann How we can Share score its in c# Script How can i access it in HTML File
     
  12. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,861
    Score from where? I believe facebook is dropping score support if you mean from there. You'll need to track score elsewhere.
     
  13. Amirraza

    Amirraza

    Joined:
    Jul 13, 2018
    Posts:
    17
    @Barthnann score from unity c# script. i want to share highest score along with the title and description using fb.sharelink();
     
  14. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,861
    You can't.

    You'll have to look into the post permission I think it is, but I haven't ever used it so I can't help you with that.