liviu-hariton/pinmeto-laravel

一个 Laravel 扩展包,提供了对 PinMeTo API 的便捷访问,使用户能够与 PinMeTo 的位置数据和指标进行交互

v0.2.0 2024-08-12 16:39 UTC

This package is auto-updated.

Last update: 2024-09-12 17:11:07 UTC


README

一个 Laravel PHP 扩展包,提供了对 PinMeTo API 的便捷访问,使用户能够与 PinMeTo 的位置数据和指标进行交互。

概述

与 PinMeTo 的集成提供了通过 PinMeTo API 获取信息和发送更新的能力,用于

  • 位置
  • 洞察力(Google™ 和 Facebook™)
  • 关键词(Google™)
  • 评论(Google™ 和 Facebook™)

目录

要求

安装

您可以通过 Composer 安装 PinMeTo Laravel 扩展包。在您的终端中运行以下命令

composer require liviu-hariton/pinmeto-laravel

Laravel 将自动注册该扩展包。

使用以下命令发布此扩展包的配置文件(并从提供的列表中选择 LHDev\PinmetoLaravel

php artisan vendor:publish

以下配置文件将发布到 config/pinmeto.php

return [
    'app_id' => env('PINMETO_APP_ID', ''), // the PinMeTo `App ID`
    'app_secret' => env('PINMETO_APP_SECRET', ''), // the PinMeTo `App Secret`
    'account_id' => env('PINMETO_ACCOUNT_ID', ''), // the PinMeTo `Account ID`
    'mode' => env('PINMETO_MODE', 'test'), // the library working mode: `live` or `test` (defaults to `test`)
];

编辑您的 .env 文件,并添加以下内容

PINMETO_APP_ID=
PINMETO_APP_SECRET=
PINMETO_ACCOUNT_ID=
PINMETO_MODE=

您可以从您的 PinMeTo 账户设置 获取 Account IDApp IDApp Secret

PINMETO_MODE 可以有 testlive 中的一个值,这取决于您想使用 PinMeTo API 的哪个阶段。

使用

安装完成后,您可以通过使用可用方法轻松检索位置数据。所有方法都将返回 JSON 格式的数据。只需在控制器的方法中注入依赖即可。

获取所有可用位置

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $locations = $pinmeto->getLocations();

        /* ... rest of your code ... */
    }
}

可选地,您也可以传递一个参数数组

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $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);

        /* ... rest of your code ... */
    }
}

获取特定位置

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $store_id = 8;
        
        $location_data = $pinmeto->getLocation($store_id);

        /* ... rest of your code ... */
    }
}

创建新位置

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $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);

        /* ... rest of your code ... */
    }
}

您还可以通过传递一个额外的参数来使用 "Upsert" 选项

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $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, true);

        /* ... rest of your code ... */
    }
}

更新现有位置

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $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);

        /* ... rest of your code ... */
    }
}

指标

获取所有位置的 Google™ 或 Facebook™ 指标数据

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $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/
        );

        /* ... rest of your code ... */
    }
}

或通过传递 Store ID 获取特定位置的指标数据

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $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
        );

        /* ... rest of your code ... */
    }
}

Google 关键词

获取所有位置的 Google™ 关键词数据

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $keywords = $pinmeto->getKeywords(
            from_date: '2024-01', // the format is `YYYY-MM`
            to_date: '2024-03' // the format is `YYYY-MM`
        );

        /* ... rest of your code ... */
    }
}

或通过传递 Store ID 获取特定位置的指标数据

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $keywords = $pinmeto->getKeywords(
            from_date: '2024-01', // the format is `YYYY-MM`
            to_date: '2024-03', // the format is `YYYY-MM`
            store_id: 8
        );

        /* ... rest of your code ... */
    }
}

评分

获取所有位置的 Google™ 或 Facebook™ 评分数据

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $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`
        );

        /* ... rest of your code ... */
    }
}

或通过传递 Store ID 获取特定位置的指标数据

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $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
        );

        /* ... rest of your code ... */
    }
}

网络类别

获取每个网络类别的列表。可用的网络有 googleapplefacebookbing

<?php

namespace App\Http\Controllers;

use LHDev\PinmetoLaravel\Pinmeto;

class YourController extends Controller
{
    public function yourMethod(Pinmeto $pinmeto)
    {
        $network_categories = $pinmeto->getNetworkCategories(
            network: 'apple'
        );

        /* ... rest of your code ... */
    }
}

许可

此库采用 MIT 许可证。有关详细信息,请参阅 LICENSE.md 文件。

PinMeTo 官方 API 文档

免责声明

我不是 PinMeTo 的关联方,但我是一名开发者,看到了他们位置服务的价值,并希望为 PHP 社区创建简化集成的工具。

虽然这个库简化了与PinMeTo位置服务API的集成,但它是我维护和支持的一个独立实体。与这些库相关的问题、疑问或咨询应直接联系我,而不是联系PinMeTo。

我非常感谢PinMeTo API的可用性,它使我能够创建这个库并增强依赖位置服务的应用程序的功能。然而,这个库的开发和维护完全是我(以及任何贡献者)的责任。

请自由地在这里的GitHub上探索这个库,进行贡献,充分利用PinMeTo强大的位置服务!

独立的 PHP 库

一个独立的PHP库也可以在这里找到:这里