自 2011 年 12 月起尝试揭开“赞”按钮的神秘面纱。
http://developers.facebook.com/docs/reference/plugins/like/
有 2 个问题:
- 如何在用户喜欢的 URL 中包含“src”和“ref”参数?我意识到这是有详细记录的,但我实际上无法在测试中做到这一点...请提供一个示例。
- 如何将喜欢它的用户的 UID 填充到他们喜欢的链接上,例如,如果他们喜欢 http://example.com ,我希望形成 http://example.com?src=fb&ref=1234567 链接
请给我举一些例子,谢谢!
最佳答案
我假设您拥有用户 ID。
您可以按如下方式指定 ref
参数,(XFBML 版本)
<fb:like href="http://example.com/fblikepage.php"
send="true" width="450" show_faces="true"
ref="<?php echo $userid; ?>"
>
</fb:like>
您无法指定 src 参数,当您指定如上所示的 ref 参数时,Facebook 会自动附加该参数。 Facebook 上的网址如下所示:http://www.example.com/fblikepage.php?fb_ref=xyz&fb_source=profile_oneline
。请参阅文档中的以下部分。
ref - a label for tracking referrals; must be less than 50 characters and can contain alphanumeric characters and some punctuation (currently +/=-.:_). The ref attribute causes two parameters to be added to the referrer URL when a user clicks a link from a stream story about a Like action: fb_ref - the ref parameter
fb_source - the stream type ('home', 'profile', 'search', 'other') in which the click occurred and the story type ('oneline' or 'multiline'), concatenated with an underscore.
当然,fb_source 参数会根据 URL 在 Facebook 上显示的位置而变化,这将由 Facebook 完成。如果你想知道用户是否通过 Facebook 访问,你可以查看 $_REQUEST
变量中是否存在 fb_source 参数,如下所示:
<?php
/* lots of code */
if(isset($_REQUEST['fb_source'])){
// we know the current user is visiting through some link on Facebook, so you can do whatever you wanted here
}
希望这有帮助。
关于javascript - Facebook Like 按钮并在链接 URL 中获取用户 UID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8420792/