liviu-hariton / pinmeto-php-api
用于与PinMeTo API交互的PHP库
Requires
- php: 8.*
- ext-curl: *
README
PinMeToAPI是一个PHP库,提供了便捷的方式访问PinMeTo API,使用户能够与PinMeTo的地点数据和指标进行交互。
概览
与PinMeTo的集成提供了通过PinMeTo API获取信息并发送更新的能力,包括:
- 地点
- 洞察力(Google™ 和 Facebook™)
- 关键词(Google™)
- 评论(Google™ 和 Facebook™)
目录
要求
- 一个PinMeTo用户账户,并且API访问已启用
- PHP >= 8.0
- PinMeToAPI使用curl扩展来处理HTTP调用。因此,您需要安装并启用PHP中的curl扩展。
- PHP中启用了json支持
安装
您可以通过在终端运行以下命令来安装PinMeToAPI PHP库
composer require liviu-hariton/pinmeto-php-api
或者将以下内容添加到您的composer.json文件中
{ "require": { "liviu-hariton/pinmeto-php-api": "^0.1.0" } }
并运行Composer的安装或更新命令以完成安装
composer install
使用
请确保包含自动加载器
require_once 'vendor/autoload.php';
使用您的PinMeTo Account ID
、App ID
和App Secret
值初始化PinMeToAPI对象。您可以从PinMeTo账户设置这里获取这些凭证。
$pinmeto = new LHDev\PinMeToAPI\PinMeToAPI([ 'app_id' => 'PINMETO_APP_ID', 'app_secret' => 'PINMETO_APP_SECRET', 'account_id' => 'PINMETO_ACCOUNT_ID', 'mode' => 'test' // or 'live' for production ]);
初始化后,您可以使用PinMeToAPI类提供的各种方法与PinMeTo API进行交互。
获取所有可用地点
$locations = $pinmeto->getLocations();
可选地,您也可以传递一个参数数组
$parameters = [ 'pagesize' => '2' // Number of locations that the request returns, default 100, max 250 'next' => '569652a91151474860f5e173', // (string) Id of starting point to next page 'before' => '569649b49c5ec8685e11175e', // (string) Id of starting point to previous page ]; $locations = $pinmeto->getLocations($parameters);
获取特定地点
$store_id = 8; $location = $pinmeto->getLocation($store_id);
创建新地点
$parameters = [ 'name' => 'Your store name', 'storeId' => 'your_store_id', 'address' => [ 'street' => 'Store address', 'zip' => 'Zipcode', 'city' => 'The City', 'country' => 'The Country', ], 'location' => [ 'lat' => 59.333755678571, 'lon' => 18.056143908447, ], ]; $pinmeto->createLocation($parameters);
您还可以通过传递额外的参数使用“Upsert”选项
$pinmeto->createLocation($parameters, true);
更新现有地点
$store_id = 8; $parameters = [ 'name' => 'The new store name', 'address' => [ 'street' => 'The new store address', 'zip' => 'Some other zipcode', 'city' => 'In some other city', 'country' => 'In some other country', ], ]; $pinmeto->updateLocation($store_id, $parameters);
指标
获取所有地点的Google™或Facebook™指标数据
$metrics = $pinmeto->getMetrics( source: 'google', // the source can be either `facebook` or `google` from_date: '2024-01-01', // the format is `YYYY-MM-DD` to_date: '2024-03-31', // the format is `YYYY-MM-DD` fields: [ 'businessImpressionsDesktopMaps', 'businessImpressionsDesktopSearch' ] // All available fields are described here https://api.pinmeto.com/documentation/v3/ );
或者通过传递Store ID获取特定地点的数据
$metrics = $pinmeto->getMetrics( source: 'facebook', // the source can be either `facebook` or `google` from_date: '2024-01-01', // the format is `YYYY-MM-DD` to_date: '2024-03-31', // the format is `YYYY-MM-DD` store_id: 8 );
Google关键词
获取所有地点的Google™关键词数据
$keywords = $pinmeto->getKeywords( from_date: '2024-01', // the format is `YYYY-MM` to_date: '2024-03' // the format is `YYYY-MM` );
或者通过传递Store ID获取特定地点的数据
$keywords = $pinmeto->getKeywords( from_date: '2024-01', // the format is `YYYY-MM` to_date: '2024-03', // the format is `YYYY-MM` store_id: 8 );
评分
获取所有地点的Google™或Facebook™评分数据
$ratings = $pinmeto->getRatings( source: 'google', // the source can be either `facebook` or `google` from_date: '2024-01-01', // the format is `YYYY-MM-DD` to_date: '2024-03-31' // the format is `YYYY-MM-DD` );
或者通过传递Store ID获取特定地点的数据
$ratings = $pinmeto->getRatings( source: 'facebook', // the source can be either `facebook` or `google` from_date: '2024-01-01', // the format is `YYYY-MM-DD` to_date: '2024-03-31', // the format is `YYYY-MM-DD` store_id: 8 );
网络类别
获取每个网络类别的列表。可用的网络有google
、apple
、facebook
和bing
。
$category_networks = $pinmeto->getNetworkCategories( network: 'apple' );
响应
对于这里描述的每个方法,响应将是JSON数据格式。请查看PinMeTo官方API文档以获取所有详细信息。
许可证
此库采用MIT许可证。有关详细信息,请参阅LICENSE.md文件。
PinMeTo官方API文档
- V2文档(地点数据)可在PinMeTo GitHub上找到
- V3文档(地点指标)可在PinMeTo API - 文档上找到
免责声明
我不是PinMeTo的关联方,但我是看到他们地点服务价值的开发者,并希望为PHP社区创建简化集成的工具。
虽然这个库便于与PinMeTo的位置服务API集成,但它是由我独立维护和支持的实体。有关这些库的任何问题、疑问或查询,应直接联系我,而不是联系PinMeTo。
我非常感激PinMeTo API的可用性,它使我能够创建这个库,并增强依赖于位置服务的应用程序的功能。然而,这个库的开发和维护完全由我(以及任何贡献者)负责。
请随意在GitHub上探索这个库,进行贡献,充分利用PinMeTo强大的位置服务!
Laravel包
还有一个Laravel包也在这里可用:这里。