Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7599817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:45:14+00:00 2026-05-30T22:45:14+00:00

I’ve reached my frustration point and am asking for help. I spent all weekend

  • 0

I’ve reached my frustration point and am asking for help. I spent all weekend learning new things in order to try and figure out how to use the goolge fusion tables API which requires authentication via Oauth 2.0. I started developing in php solely because I was able to find some examples that helped me down the path. Prior to a few days ago I knew very little in this area and if you’re wondering why I tried a certain approach in my code below instead of some other approach the simple answer is that this is all I found.

I was able to successfully develop a page that would solicit a code response from Google for access to my own personal profile. I was also able to successfully develop a page located at the required redirect location that would take that code, pass it back to google and solicit an access token and a refresh token, which were successfully written to file in a password protected directory on my website. I was also able to successfully develop a page that would pass the refresh token back to google and receive an updated access token and write that to file, if/when necessary. All of this was done in php.

Now my primary objective for all of this is to be able to write fusion table styles to new fusion tables. I currently have a number of fully developed fusion tables (along with the proper styling) in my google docs account. I also uploaded a test fusion table that has fully developed data but has not yet been styled. I was attempting to simply write some code that would get the styling from an existing fully developed FT and write the same style into this test FT.

I have been able to successfully get the style JSON object from the existing FT and modify that JSON object such that it’s table id property is changed to the test FT so that the JSON object may be passed back to the test FT and written into the styles.

However when I try to pass back the styling data to google to update the test FT via POST I get an error that prints out to ” { “error”: { “errors”: [ { “domain”: “global”, “reason”: “authError”, “message”: “Invalid Credentials”, “locationType”: “header”, “location”: “Authorization” } ], “code”: 401, “message”: “Invalid Credentials” } }”

It’s entirely possible that I am formatting the POST incorrectly. However, I am not doing anything fancy (so far) with the access token. I’ve simply made the request, received it from google and copied and pasted it directly into the code so there could be no issues on assigning variables and/or timing out.

Here is my code for what I had hoped to be a pretty straightforward process, with certain sensitive data items redacted but described. Please offer suggestions if you can.

<html>
<head>
<title>Google Fusion Tables API Example</title>
</head>
<body>

<?php

  //table id of the FT that has fully developed styling.
  $strTableID = '1r8CRtGalQ3vC0zd_xmsChzjALlriiV5UDYFVOJU';

  //prepare your cURL request for GET of FT styling data from existing table.  Initialize it, set the options and then execute it.
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/fusiontables/v1/tables/'.$strTableID.'/styles/1?&key=redactedKey');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $result = curl_exec($ch);
  curl_close($ch);
  //print result to see if it works (it works)
  echo "<br> Result: $result";

  //the result returns as a JSON object.  Decode the object into a standard array, then display the individual elements of the array to see that it worked.
  $jsonResult = json_decode($result,true);
  echo "<br><br> JSON Result: ".$jsonResult['polygonOptions']['fillColorStyler']['columnName'];
  echo "<br> Table ID: ".$jsonResult['tableId'];

  //update the tableID and the bound column
  //this is the table id of the test FT
  $strTableID = '1CnecsDL67YHjBzSmfLjODRWxHDuC39frZEaTEKQ';
  $jsonResult['tableId'] = $strTableID;
  $jsonResult['polygonOptions']['fillColorStyler']['columnName'] = 'redacted column name';
  //print out the updated new JSON elements to see that they were properly applied (works)
  echo "<br><br> JSON Result: ".$jsonResult['polygonOptions']['fillColorStyler']['columnName'];
  echo "<br> Table ID: ".$jsonResult['tableId'];

  //Re-encode the array into a JSON object
  $jsonWrite = json_encode($jsonResult);


  $postField = 'access_token=redactedAccessToken in the form of ya29.AHE...Rdw';
  //set your header type so that Google knows what type of data it is receiving
  $arrHeader = array('Content-Type'=>'application/json');
  $url = "https://www.googleapis.com/fusiontables/v1/tables/".$strTableID."/styles";

  //prepare your cURL request.  Initialize it, set the options and then execute it.
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeader);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postField.'&'.$jsonWrite);
  $result = curl_exec($ch);
  curl_close($ch);
  //print out the response to see if it worked (doesn't work)
  echo "<br><br>Post Result: $result";

?>
</body>
</html>

I have also tried one alternative method. I’ve tried putting the access token into the header of the POST as such:

$arrHeader = array('Content-Type'=>'application/json', 'access_token'=>'redactedAccessToken in the form of ya29.AHE...Rdw');

And then simplifying the Post Fields options as such:

curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonWrite);

This returns a different error: “{ “error”: { “errors”: [ { “domain”: “global”, “reason”: “required”, “message”: “Login Required”, “locationType”: “header”, “location”: “Authorization” } ], “code”: 401, “message”: “Login Required” } }”

Please provide any assistance if you can. Thank you for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:45:15+00:00Added an answer on May 30, 2026 at 10:45 pm

    The access token should either sent as an Authorization: Bearer HTTP header OR as the value of access_token parameter in the URL.

    To send as the Authorization: Bearer header, use the $arrHeader variable again, but update the line of code to the following:

    $arrHeader = array('Content-Type'=>'application/json', 'Authorization'=>'Bearer <your_access_token>');
    

    Or, if you want to use the access_token parameter, update the following line and do not send the access token in the body of the post:

      curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/fusiontables/v1/tables/'.$strTableID.'/styles/1?&key=redactedKey&access_token=<your_access_token>');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.