使用 Google My Business API 和 PHP 更新/修補本地帖子 (Updating/Patching a Local Post with Google My Business API and PHP)


問題描述

使用 Google My Business API 和 PHP 更新/修補本地帖子 (Updating/Patching a Local Post with Google My Business API and PHP)

我正在嘗試使用 curl 更新/修補特定的 GMB 本地帖子。對於此示例,我只是嘗試更新帖子的摘要

這是我的代碼:

    $url = "https://mybusiness.googleapis.com/v4/".$postId."?updateMask=1";

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $pQuery = array(
        "summary" => $postMessage
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($pQuery));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer '.$access_token.'', 'Content‑Type: application/json', 'Content‑Length: ' . strlen(json_encode($pQuery))));

    $updatePostDetails = curl_exec($ch);

我沒有收到任何錯誤,但是我得到的響應正文與以前的本地帖子相同,忽略了我更新的新 summary

我假設我的問題來自 updateMask 參數,但我找不到如何讓它工作。

感謝您的幫助。


參考解法

方法 1:

updateMask parameter expects path of the field that needs change. So you should provide as updateMask=summary. So your URL should be as

   $url = "https://mybusiness.googleapis.com/v4/".$postId."?updateMask=summary";

(by mckaymentalSudheer m)

參考文件

  1. Updating/Patching a Local Post with Google My Business API and PHP (CC BY‑SA 2.5/3.0/4.0)

#curl #google-my-business-api #PHP






相關問題

如何在所有 PayPal 交易中退還費用 (How to return fee in all PayPal transactions)

Cú pháp lệnh curl để đăng ký device_token trên Urban Airship là gì? (What is curl command syntax for device_token registration on Urban Airship?)

Nhận thời lượng video trên youtube từ URL với bash (Get youtube video duration from URL with bash)

đăng dữ liệu json với php curl cho đa phần / dữ liệu biểu mẫu để tải lên tệp nếu cakephp 2 (post json data with php curl for multipart/form-data for file upload vía cakephp 2)

ApacheMonitor 上的捲曲錯誤 (Curl error on ApacheMonitor)

從 ASP.net 使用 PHP 中的 POST 數據抓取數據 (Scraping data with POST data in PHP from ASP.net)

收聽推送消息? (Listen to a push message?)

在 PHP 中使用 cURL 的 RAW POST (RAW POST using cURL in PHP)

使用 php 和 curl 更新 mediawiki (using php and curl to update mediawiki)

在 Makefile 中鏈接 cURL (Linking cURL in Makefile)

將我的 .php 輸出發送到 curl 命令,該命令使用機器人在電報上向我發送消息 (Send my .php output to a curl command that messages me on telegram using a bot)

使用 Google My Business API 和 PHP 更新/修補本地帖子 (Updating/Patching a Local Post with Google My Business API and PHP)







留言討論