quangtam/opengraph
Composer 安装命令:
composer require quangtam/opengraph
包简介
A Laravel package to fetch website Open Graph metadata.
README 文档
README
A Laravel package to fetch Open Graph metadata of a website.
Features
-
Easily fetch metadata of a url. Laravel OpenGraph fetch all the metadata of a URL.
-
Supports language specific metadata. Laravel OpenGraph can fetch metadata in a specific language if webpage supports.
-
Supports twitter metadata. Laravel OpenGraph supports twitter OG data too.
-
Verify image URL. Laravel OpenGraph verifies that the image url in the image metadata is valid or not.
Demo
curl https://laravelopengraph.herokuapp.com/api/fetch?url=ogp.me&allMeta=true&language=en_GB
How to use Laravel OpenGraph
Article can be found on medium blog: https://hackernoon.com/how-to-fetch-open-graph-metadata-in-laravel-2d5d674904d7
Installation
Perform the following operations in order to use this package
- Install via composer
composer require "quangtam/opengraph"
If you do not run Laravel 5.5 (or higher), then add the service provider in config/app.php:
-
Add Service Provider Open
config/app.phpand addshweshi\OpenGraph\Providers\OpenGraphProvider::class,to the end ofprovidersarray:'providers' => array( .... quangtam\OpenGraph\Providers\OpenGraphProvider::class, ),Next under the
aliasesarray:'aliases' => array( .... 'OGMeta' => quangtam\OpenGraph\Facades\OpenGraphFacade::class ),
If you do run the package on Laravel 5.5+, package auto-discovery takes care of the magic of adding the service provider.
Requirements
- You need to install the DOM extension.
How to use
-
After following the above steps,
use OGMeta; $data = OGMeta::fetch("https://unsplash.com/");this will give you an array like this..
array ( 'title' => 'Beautiful Free Images & Pictures | Unsplash', 'description' => 'Beautiful, free images and photos that you can download and use for any project. Better than any royalty free or stock photos.', 'type' => 'website', 'url' => 'https://unsplash.com/', 'image' => 'http://images.unsplash.com/photo-1542841791-1925b02a2bbb?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEyMDd9&s=aceabe8a2fd1a273da24e68c21768de0', 'image:secure_url' => 'https://images.unsplash.com/photo-1542841791-1925b02a2bbb?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEyMDd9&s=aceabe8a2fd1a273da24e68c21768de0', )You can also pass an optional parameter either true or false along with url. When set false it will only fetch basic metadata and in case of true it will fetch all the other optional metadata as well like audio, video, music and twitter metatags as well.
$data = OGMeta::fetch("https://unsplash.com/", true);this will give you an array like this..
array ( 'charset' => 'UTF8', 'viewport' => 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimal-ui', 'mobile-web-app-capable' => 'yes', 'apple-mobile-web-app-capable' => 'yes', 'apple-mobile-web-app-title' => 'Unsplash', 'application-name' => 'Unsplash', 'author' => 'Unsplash', 'msapplication-config' => 'browserconfig.xml', 'msapplication-TileColor' => '#ffffff', 'msapplication-TileImage' => 'https://unsplash.com/mstile-144x144.png', 'theme-color' => '#ffffff', 'description' => 'Beautiful, free images and photos that you can download and use for any project. Better than any royalty free or stock photos.', 'twitter:site' => '@unsplash', 'twitter:title' => 'Beautiful Free Images & Pictures | Unsplash', 'twitter:description' => 'Beautiful, free images and photos that you can download and use for any project. Better than any royalty free or stock photos.', 'twitter:url' => 'https://unsplash.com/', 'twitter:card' => 'summary_large_image', 'twitter:image' => 'https://images.unsplash.com/photo-1546486610-e9fe4f1e6751?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEyMDd9', 'title' => 'Beautiful Free Images & Pictures | Unsplash', 'type' => 'website', 'url' => 'https://unsplash.com/', 'image' => 'http://images.unsplash.com/photo-1546486610-e9fe4f1e6751?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEyMDd9', 'image:secure_url' => 'https://images.unsplash.com/photo-1546486610-e9fe4f1e6751?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEyMDd9', )To fetch the metadata in a specific language you can pass the language as the third argument, this value will be used as the Accept-Language header.
$url = "https://ogp.me", $allMeta = true, // can be false $language = 'en' // en-US,en;q=0.8,en-GB;q=0.6,es;q=0.4 $data = OpenGraph::fetch($url, $allMeta, $language);
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING and CODE OF CONDUCT for details.
License
The MIT License (MIT). Please see License File for more information.
Happy coding!
quangtam/opengraph 适用场景与选型建议
quangtam/opengraph 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 quangtam/opengraph 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 quangtam/opengraph 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-30