我如何检索资源的og / meta属性? [英] How can I retrieve og/meta attributes of a resource?

查看:106
本文介绍了我如何检索资源的og / meta属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个可以在用户的​​Twitter上检索推文的应用程序。

这些供稿包含指向外部资源的链接,例如Artciles,网页或YouTube视频。

我在Twitter API中使用了这些提要的JSON,但没有包含这些提供的 og:属性内容。我想赶上他们,并显示到我的网站。



例如

 < pre $>这个 StackOverflow的问题:

meta name =og:typecontent =website/>
< meta name =og:imagecontent =http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=fde65a5a78c6/>
< meta name =og:descriptioncontent =我有一些元素,例如:
& lt; div class =& quot;按钮17-facebook-dashboard-check& amp; amp; lt; Elem1& lt; div& gt;
& lt; div class =& quot;按钮18-google-dashboard-check& quot;& amp; amp; amp; lt; div class =& quot; Elem2& lt; div& gt;
& lt; div class =& quot; button/>
< meta name =og:urlcontent =https://stackoverflow.com/questions/19001883/how-can-i-check-classes-that-ends-with/>

我想为每条推文上的每个共享资源捕获这些信息。
所以我想我会为每个推文(对于我来说是一个盒子)做一个ajax请求客户端,下载html并解析它,检索 og:title og:description og:type og:image



这是最好的选择吗?在JavaScript / Jquery中解析这些数据是什么?

解决方案

这些 og:属性是 Open Graph Protocol 属性,有很多方法可以获取这些数据:你应该检查 Open Graph Protocol解析器,这对你来说可能非常有用,而且

您也可以查看关于PHP解析的StackOverflow问题和这个 Opengraph PHP解析器和动态使用它们与ajax调用。



最后,这非常有趣,可以真正帮助你。



希望你能找到你需要的东西! ;)

I'm making an application that retrieve tweets on Twitter of a user.

Those feeds contains links to external resources, such as Artciles, Webpage or YouTube video.

I get trought the Twitter API the JSON of these feeds, but there arent included the og: attributes of the content. And I'd like to catch them and show to my website.

Such as this question of StackOverflow:

<meta name="og:type" content="website" />
<meta name="og:image" content="http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=fde65a5a78c6"/>
<meta name="og:title" content="How can I check classes that ends with?" />
<meta name="og:description" content="I have some elements such as:
    &amp;lt;div class=&quot;button 17-facebook-dashboard-check&quot;&amp;gt;Elem1&amp;lt;div&amp;gt;
    &amp;lt;div class=&quot;button 18-google-dashboard-check&quot;&amp;gt;Elem2&amp;lt;div&amp;gt;
    &amp;lt;div class=&quot;button " />
<meta name="og:url" content="https://stackoverflow.com/questions/19001883/how-can-i-check-classes-that-ends-with"/>

I'd like to catch those informations for each shared resource on each tweet. So I think I'll, for each tweet (which for me is a box) do an ajax request client side, download the html and parse it, retrieving og:title, og:description, og:type and og:image.

Is this the best approch? What's about parse this data in Javascript/Jquery?

解决方案

These og: attributes are Open Graph Protocol attributes, there are many way to get these datas : you should check the codes of Open Graph Protocol parser which may be very usefull for you, and this PHP and jQuery Facebook link parser.

You can also check this StackOverflow Question about PHP parsing and this Opengraph PHP parser and dynamically use them with ajax calls.

Finally, this StackOverflow question about JQuery and pure JavaScript parsing is very interesting and could really help you.

Hope you'll find what you need ! ;)

这篇关于我如何检索资源的og / meta属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆