adnanhussainturki / google-my-business-php
GoogleMyBusiness的GOTO PHP包装器
0.1
2021-01-28 05:38 UTC
Requires
- google/apiclient: ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-08-28 13:27:25 UTC
README
谷歌私自在GoogleMyBusiness API向开发者提供。由于是私有的,因此该API的SDK不在Google Services PHP SDK中。此项目提供了一种简单易行的使用GoogleMyBusiness API的方式。
请求访问权限
由于是私有API,您需要通过以下表格请求对相同API的访问权限,用于您的Google项目。您可能需要提供项目ID和用例。
凭证
一旦您的API请求得到批准,您需要生成凭证,即client_id和client_secret。此外,您还需要为以下作用域生成刷新令牌
https://www.googleapis.com/auth/business.manage
如果您不太了解如何刷新令牌,请遵循以下说明
- 在Google Developer Console中生成您的API凭证时,在授权javascript字段中输入
https://google.myphpnotes.com
,并在redirect_uri字段中输入https://google.myphpnotes.com/callback.php
。 - 然后,转到
https://google.myphpnotes.com
- 在给定的字段中提供您的客户端ID和客户端密钥,并添加以下作用域https://www.googleapis.com/auth/business.manage
- 提交后,您将被要求授权访问您的Google账户。选择相应的账户并允许给定的作用域。
- 重定向后,您将获得一些重要信息,如access_token和refresh_token。
- 从那里记下刷新令牌。
安装
您可以使用以下命令通过composer将此库安装到项目中
composer require adnanhussainturki/google-my-business-php
列出账户
GMB的工作原理是这样的。您的Google账户拥有许多账户(通常有一个)并且每个账户包含多个地点。
$gmb = new GoogleMyBusiness("APP_KEY", "APP_SECRET");
$gmb->setRefreshToken("_REFRESH_TOKEN_");
$account = new Account();
$account->provideClient($gmb);
$accounts = $account->list();
$firstAccount = $accounts[0];`
列出地点
$gmb = new GoogleMyBusiness("APP_KEY", "APP_SECRET");
$gmb->setRefreshToken("_REFRESH_TOKEN_");
$account = new Account();
$account->provideClient($gmb);
$accounts = $account->list();
$firstAccount = $accounts[0];
$locations = $accounts[0]->locations();
$firstLocation = $locations[0];
列出地点帖子
$gmb = new GoogleMyBusiness("APP_KEY", "APP_SECRET");
$gmb->setRefreshToken("_REFRESH_TOKEN_");
$account = new Account();
$account->provideClient($gmb);
$accounts = $account->list();
$firstAccount = $accounts[0];
$locations = $accounts[0]->locations();
$firstLocation = $locations[0];
$posts = $firstLocation->posts();
$firstPost = $posts[0];
列出地点媒体
$gmb = new GoogleMyBusiness("APP_KEY", "APP_SECRET");
$gmb->setRefreshToken("_REFRESH_TOKEN_");
$account = new Account();
$account->provideClient($gmb);
$accounts = $account->list();
$firstAccount = $accounts[0];
$locations = $accounts[0]->locations();
$firstLocation = $locations[0];
$posts = $firstLocation->posts();
$firstPost = $posts[0];
$medias = $firstLocation->medias();
$firstMedia = $medias[0];
创建媒体
$media = new Media;
$media->provideClient($gmb); // GoogleMyBusiness Client for making credentials available to the media class.
$media->setLocationId($firstLocation->getLocationId()); // Location ID
$media->setCategory("ADDITIONAL");
$media->setFormat('PHOTO');
$media->setSourceUrl("https://cdn.torksky.com/projects/torksky_control/production/products/06019E50K0/ff37c4a25fcf48975831153cc376dfdd.jpeg");
$media->setDescription("Bosch GAS 15");
$media = $media->create();
创建帖子
$post = new Post;
$post->provideClient($gmb);
$post->setLocationId($firstLocation->getLocationId());
$post->setCallToAction("ORDER", "https://torksky.com/catalogue/70d1f7b121c397fafc00c6127e7d14c2/view");
$post->setName("Bosch GAS 15");
$post->setDescription("Bosch GAS 15 order now");
$post->setLanguageCode("en");
$post->addMedia($media);
$post->create();
限制
通过API
- 您不能添加产品
- 您不能在帖子中添加优惠
- 您不能在帖子中添加超过一个媒体
- 可能还有其他限制。您可以告诉我们。
通过库
此库目前只关注以下功能
- 列出账户
- 列出地点
- 列出每个地点的帖子
- 列出每个地点的媒体
- 为地点创建媒体
- 为地点创建帖子
- 请自由贡献/提出问题。
给我买杯咖啡
如何贡献
- 创建分支,进行更改并发送pull请求。
- 提出问题
许可证
Apache 2.0许可。您可以在这里查看其详细信息。