如何在php中使用Google MyBusiness API

时间:2017-01-25 00:53:14

标签: php api oauth-2.0 google-my-business-api

我正在使用Google MyBsiness API获取所有商家评论。 但我无法使用PHP语法和GET,POST方法在MYBusiness中使用。

誓言之后是我用于获取评论的代码

$mybusinessService = new Google_Service_Mybusiness($client);
$accessToken = file_get_contents($credentialsPath);

$reviews = $mybusinessService->accounts_locations_reviews;
echo '<pre>';print_r($reviews->get('ArtechDev'));exit;

但是我收到错误404(致命错误:带有消息的未捕获异常'Google_Service_Exception')

我确信我不知道如何传递param以及它需要哪些东西。我已登录为具有位置'ArtechDev'的帐户也请 让我知道我在哪里可以打电话

https://mybusiness.googleapis.com/v3/accounts/account_name/locations/location_name/reviews

由于

2 个答案:

答案 0 :(得分:2)

我希望你很久以前找到了问题的答案,无论如何我会希望别人帮助你。

/*$accounts previusly populate*/
/*(GMB - v4)*/
$credentials_f = "google_my_business_credentials_file.json";
$client = new Google_Client();
$client->setApplicationName($aplicattion_name);
$client->setDeveloperKey($developer_key);
$client->setAuthConfig($credentials_f);  
$client->setScopes("https://www.googleapis.com/auth/plus.business.manage");
$client->setSubject($accounts->email);   
$token = $client->refreshToken($accounts->refresh_token);
$client->authorize();

$locationName = "accounts/#######/locations/########";

$mybusinessService = new Google_Service_Mybusiness($client);

$reviews = $mybusinessService->accounts_locations_reviews;

do{
    $listReviewsResponse = $reviews->listAccountsLocationsReviews($locationName, array('pageSize' => 100,
                        'pageToken' => $listReviewsResponse->nextPageToken));

    $reviewsList = $listReviewsResponse->getReviews();
    foreach ($reviewsList as $index => $review) {
        /*Accesing $review Object

        * $review->createTime;
        * $review->updateTime;
        * $review->starRating;
        * $review->reviewer->displayName;
        * $review->reviewReply->comment;
        * $review->getReviewReply()->getComment();
        * $review->getReviewReply()->getUpdateTime();
        */

    }

}while($listReviewsResponse->nextPageToken);

答案 1 :(得分:-1)

$ acounts来自:

import cv2
import numpy as np
import pytesseract

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

# Load image, grayscale, threshold, invert
image = cv2.imread('1.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
result = 255 - thresh

# Perfrom OCR with Pytesseract
data = pytesseract.image_to_string(result, config='--psm 3')
print(data)

cv2.imshow('result', result)
cv2.waitKey()