1

我正在尝试为我的网站实施“登记”按钮。主要目的是:当用户点击按钮时,Facebook共享对话框将打开,用户将在自定义位置进行检查。用户信息不会被自动发布,并且信息不会被设置,以免它违反Facebook政策。 正如我所知,这可能发生在Facebook Open Graph的故事中。我已经添加了一个“Place”选项作为Open Graph Object类型。我知道要做到这一点,我的应用程序需要“publish_actions”权限,我的应用程序处于开发者模式,所以这不是问题。我使用Facebook Javascript SDK。因此,代码是这样的:我的网站的Facebook登记按钮

这是OG标记(Facebook给出的):

<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# place: http://ogp.me/ns/place#"> 
    <meta property="fb:app_id"    content="my-app-id" /> 
    <meta property="og:type"     content="place" /> 
    <meta property="og:url"     content="my-url" /> 
    <meta property="og:title"     content="my-place-name" /> 
    <meta property="og:image"     content="sample-url-image" /> 
    <meta property="place:location:latitude" content="Sample Location: Latitude" /> 
    <meta property="place:location:longitude" content="Sample Location: Longitude" /> 

,这是调用共享对话框(也被Facebook给出)功能:

function share() 
{ 
    FB.api(
     'me/objects/place', 
     'post', 
     {'object': { 
     'og:url': 'my-url', 
     'og:title': 'my-place-name', 
     'og:type': 'place', 
     'og:image': 'sample-url-image', 
     'og:description': '', 
     'fb:app_id': 'my-app-id', 
     'place:location:latitude': 'Sample Location: Latitude', 
     'place:location:longitude': 'Sample Location: Longitude' 
     }}, 

    function(response) { 
     // handle the response 
     // for example (using Jquery) 
     $('#element').append('shared'); 
     } 
    ); 
} 

,这是该函数的调用:

<span onclick="share()">click to share</span> 
<div id="element"></div> 

的问题是,代码不工作nd共享对话框将不会打开。我的错误在哪里?

+0

是否有脚本,你应该为共享按钮加载?我猜测,如果你看看开发工具,你会看到一个'Uncaught ReferenceError:FB.api not defined(...)' – tymcsilva

+0

FB.api()在加载了Facebook JavaScript SDK后调用。 – webtech

+0

您在控制台中遇到什么错误? – tymcsilva

回答

0

最后,我创建它只是一个共享按钮。可以选择检查是否真的发布,之后不会取消。

FB.ui({ 
    method: 'share', 
    mobile_iframe: true, 
    title: 'My title', 
    href: 'url to share', 
    picture: 'image URL', 
    description: 'The description' 
    }, function (response) { 
    if (response && !response.error_message) { 
    alert('Thank you for sharing!'); 
    } else { 
    alert('You have cancelled the share.'); 
    } 
    }); 
},{scope: 'email'}); 
相关问题