web 分享到facebook
利用meta 使自己的页面变为一种富媒体文件,利用facebook的 open Graph
比如你的html页面想要以图片的形式被分享
<meta property="og:image" content="http://food.png">
<meta property="og:image:secure_url" content="https://food.png">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="500">
|
元标签 |
说明 |
|---|---|
|
|
图片的网址。要在发布图片后更新图片,请为新图片使用新网址。系统会根据之前的网址缓存图片,除非网址更改,否则不会更新图片。 |
|
|
与 |
|
|
图片的 https:// 网址 (非本地) |
|
|
图片的 MIME 类型。 |
|
|
以像素为单位的图片宽度。指定图片的高度和宽度,确保图片在第一次分享时正确加载。 |
|
|
以像素为单位的图片高度。指定图片的高度和宽度,确保图片在第一次分享时正确加载。 |
当然 还可以分享视频音频文本等;详见https://developers.facebook.com/docs/sharing/opengraph/object-properties
完整代码示例
将代码示例复制粘贴到您的网站。将 data-href 值调整为您网站的网址。然后使用 og:*** 元标记调整链接预览。og:url 和 data-href 应使用相同的网址。
<html>
<head>
<title>Your Website Title</title>
<!-- You can use Open Graph tags to customize link previews.
Learn more: https://developers.facebook.com/docs/sharing/webmasters -->
<meta property="og:url" content="https://www.your-domain.com/your-page.html" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Your Website Title" />
<meta property="og:description" content="Your description" />
<meta property="og:image" content="https://www.your-domain.com/path/image.jpg" />
</head>
<body> <!-- Load Facebook SDK for JavaScript -->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script> <!-- Your share button code -->
<div class="fb-share-button"
data-href="https://www.your-domain.com/your-page.html"
data-layout="button_count">
</div> </body>
</html>
类似的还有收藏 此处不做详细接收 详见:https://developers.facebook.com/docs/plugins/share-button/#example
可以使用分享对话框来让用户从您的应用分享开放图谱动态。
若要集成开放图谱动态的分享对话框:
详见: https://developers.facebook.com/docs/opengraph/getting-started
分享对话框代码
以下对话框代码示例可以通过帖子中的“赞”操作将开放图谱动态分享至用户的时间线。

将脚本加入在上面配置的应用。在脚本中,使用应用编号替换 your-app-id。
<script type="text/javascript"> // Initialize the Facebook JS SDK.
window.fbAsyncInit = function() {
FB.init({
appId : 'your-app-id',
autoLogAppEvents : true,
xfbml : true,
version : 'v3.1'
}); // Put additional init code here
}; // Load the Facebook JS SDK Asynchronously
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk')); // Custom function to call when user initiates a share
function ogShare() {
FB.ui({
method: 'share_open_graph',
action_type: 'og.likes',
action_properties: JSON.stringify({
object:'https://developers.facebook.com/docs/opengraph/getting-started',
})
}, function(response){
// Debug response (optional)
console.log(response);
});
} </script>
现在,您可以将 ogShare() 功能与网页应用中的按钮相关联。当用户点击该按钮时,将触发分享对话框,并在其标题中显示“赞”动作。
类似的分享到其他网站 可以参考:
https://blog.csdn.net/yq_dxp1218/article/details/79417040
https://www.zcfy.cc/article/the-essential-meta-tags-for-social-media-css-tricks-658.html
分享到whatApp
web 分享到facebook的更多相关文章
- web 分享代码片段
<div class="bshare-custom icon-medium-plus"><a title="分享到QQ空间" class=&q ...
- 安卓开发分享功能,分享到facebook网页上不显示图片的问题
最近公司要上分享功能,分享的地方包括微信,qq,facebook,功能完成后,发现分享到facebook的内容只有文字可以显示,图片不显示,其中图片存储是使用七牛的服务器:而分享到微信和qq都可以正常 ...
- 分享前端Facebook及Twitter第三方登录
最近公司要求做海外的第三方登录:目前只做了Facebook和Twitter;国内百度到的信息太少VPN FQ百度+Google了很久终于弄好了.但是做第三方登录基本上都有个特点就是引入必须的js,设置 ...
- 移动端折腾国外分享(facebook、twitter、linkedin)
一.前言 国内做HTML5页面,关注最多就是微信分享了,之前也写过关于微信分享的文章,可以点击查看:分享相关文章 再者,就是国内的其它分享,比如常用的新浪微博.腾讯微博.QQ空间等等,最方便的就是直接 ...
- 安卓,分享到facebook的若干种方法汇总
近期做了facebook的分享功能,遇到了很多问题,这里总结一下,供大家参考,不足之处还请大家指正. facebook分享方式: 1.通过intent调用调用本地facebook应用方式 支持单独分享 ...
- java web分享ppt大纲 -- servlet容器简介
今天在公司分享了java web的ppt,把ppt大纲放在这里,希望可以帮助需要的人 servlet容器简介 定义 狭义上的,servlet容器为java Web应用提供运行时环境,负责管理servl ...
- 网页分享到facebook
一.在网页头部加入如下代码: <meta property="og:url" class="fb_url" content="分享url&quo ...
- web分享QQ好友、QQ空间、新浪微博的api接口
QZone: "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={{URL}}&title={{TITL ...
- 基于bshare分享平台,在一个页面上实现多个不同内容的web分享
<!--引入bshare SDK--><script type="text/javascript" charset="utf-8" src=& ...
随机推荐
- [LeetCode] K-th Symbol in Grammar 语法中的第K个符号
On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace ...
- Web Driver 8中定位方法 ——基于python语言
WebDriver提供了八种元素定位方法,在python 语言中,方法如下: id定位:find_element_by_id("id值"):id属性是唯一的. 1 driver ...
- C# WinForm:无法访问已释放的对象
C#在父窗口中调用子窗口的过程: 1. 创建子窗口对象 2. 显示子窗口对象 笔者的程序中,主窗体MainFrm通过菜单调用子窗口ChildFrm.在窗体中定义了子窗口对象,然后在菜单项点击事件中 ...
- nodejs----微信注册测试号获取token
var PORT=8081; //监听8080端口号 var http=require('http'); var qs=require('qs'); var TOKEN='yezhenxu'; //必 ...
- DevExpress GridControl复合表头(多行表头)设置
关于DevExpress.XtraGrid的复合表头或多行表头的示例,界面如下图所示 1.首先要把DevExpress的GridControl转换为BandedGridView 2.设置显示列及绑定的 ...
- wpf mvvm 实例
1.程序结构如图所示: 2.Model实现 在Model文件夹下新建业务类StudentModel,代码如下: public class StudentModel : INotifyPropertyC ...
- [04-05]box框模型(Box Model)定义了元素框处理元素内容、内边距、边框和外边距的方式
实际占有的宽 = width + 2padding(内边距) + 2border(边框) + 2margin(外边距) 实际占有的高 = height + 2padding + 2border + 2 ...
- 【Python基础】lpthw - Exercise 41 学习面向对象术语
一.专有词汇 类(class):告诉python创建新类型的东西. 对象(object):两个意思,即最基本的东西,或者某样东西的实例. 实例(instance):让python创建一个类时得到的东西 ...
- scrapy_redis实现爬虫
1.scrapy_redis的流程 在scrapy_redis中,所有的带抓取的对象和去重的指纹都存在所有的服务器公用的redis中 所有的服务器公用一个redis中的request对象 所有的req ...
- 【Pattern】-NO.150.Pattern.1 -【Pattern UML】
Style:Mac Series:Java Since:2018-09-10 End:2018-09-10 Total Hours:1 Degree Of Diffculty:5 Degree Of ...
