douju6651 2018-01-08 21:19
浏览 68

使用HTTP请求使用spreadsheets.values.update方法Google API

I wish to use the following API to update one cell: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update

I was unable to get the API library to work with my package, so I've been using HTTP requests for other situations.

Here is a similar approach for this situation:

$request_url = "https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/Sheet2!A2";
$access_token = get_access_token();
$headers = array();
$headers[] = 'Authorization: Bearer ' . $access_token;
try {
  $data = array('valueInputOption' => 'RAW',
                'values' => [0 => strval($post_id)]);
  $curl = new \MyApp\Http\Curl($request_url, array(
      CURLOPT_HTTPHEADER => $headers,
      CURLOPT_CUSTOMREQUEST => "PUT",
      CURLOPT_POSTFIELDS => http_build_query($data)
  ));
  $response_json = $curl->__toString();
  var_dump($response_json);
} catch (\RuntimeException $ex) {
  die(sprintf('Http error %s with code %d', $ex->getMessage(), $ex->getCode()));
}

But I get:

string(573) "{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"values[0]\": Cannot bind query parameter. Field 'values[0]' could not be found in request message.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"values[0]\": Cannot bind query parameter. Field 'values[0]' could not be found in request message."
          }
        ]
      }
    ]
  }
}
"

How do I post the values in this API request?

Here is it working on the Try this API part of the Google page.

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?