Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

javascript - FB.ui share set the title, message and image

I'm using FB.ui to share a page to Facebook and I'm trying to set the title and message (image if possible but not important). I have this in my site header

<meta property="og:title" content="Your title here" />
<meta property="og:description" content="your description here" />

And my javascript code is

FB.ui({
      method: 'share',
      href: document.URL,
    }, function(response){

        //TODO Proper response handling
        log(response); 
        if (typeof response != 'undefined') {
            alert('Thanks for sharing');
        }
    }); 

From what I've read I just need to og:titleand og:description to set the title and message, but that doesn't seem to work.

Current the title is either coming from part of the part title, or an alt tag on an image, and the message is being populated from just a random paragraph tag.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Facebook documentation says that "share" method has only href parameter, but I have found it is not true. You can use very similar parameters to the "feed" method. This is what I have used and works:

    FB.ui(
    {
        method: 'share',
        href: 'your_url',     // The same than link in feed method
        title: 'your_title',  // The same than name in feed method
        picture: 'path_to_your_picture',  
        caption: 'your_caption',  
        description: 'your_description',
     },
     function(response){
        // your code to manage the response
     });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...