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 8333927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:10:57+00:00 2026-06-09T03:10:57+00:00

Problems in access to Google API OAuth2 Service Account with google-api-php-client . What I

  • 0

Problems in access to Google API OAuth2 Service Account with google-api-php-client. What I surprised to discover is this part of code from example of a JWT claim set in Google Dev returning wrong JWT Claim set when for some reason JWT Header pass true what making me feel like UTF-8 serialization with json_encode() creating an error here.

  $JWT_Header = array(
    "alg" => "RS256",
    "typ" => "JWT"
  );
  $JWT_Body = array(
    "iss" => "761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com",
    "scope" => "https://www.googleapis.com/auth/prediction",
    "aud" => "https://accounts.google.com/o/oauth2/token",
    "exp" => 1328554385,
    "iat" => 1328550785
  );

  $segments = array(
    rtrim(strtr(base64_encode(json_encode($JWT_Header)), '+/', '-_'), '='),
    rtrim(strtr(base64_encode(json_encode($JWT_Body)), '+/', '-_'), '=')
  );
  //echo '<pre>'; print_r($segments); echo '</pre>';

different from what is described in Google Dev: Encoding the JWT Claim Set example of output

/*
    Output: 

    JWT header:
    Google Dev    eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.
     My output    eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.

    JWT Claim set:
    Google Dev    eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvcHJlZGljdGlvbiIsImF1ZCI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbS9vL29hdXRoMi90b2tlbiIsImV4cCI6MTMyODU1NDM4NSwiaWF0IjoxMzI4NTUwNzg1fQ.
     My output    eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOlwvXC93d3cuZ29vZ2xlYXBpcy5jb21cL2F1dGhcL3ByZWRpY3Rpb24iLCJhdWQiOiJodHRwczpcL1wvYWNjb3VudHMuZ29vZ2xlLmNvbVwvb1wvb2F1dGgyXC90b2tlbiIsImV4cCI6MTMyODU1NDM4NSwiaWF0IjoxMzI4NTUwNzg1fQ.
*/

Any suggestions?

  • 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-06-09T03:10:58+00:00Added an answer on June 9, 2026 at 3:10 am

    It doesn’t seem to be related to UTF-8 in any way. To debug, just apply the same algorithm backwards:

    $output = array(
        'eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvcHJlZGljdGlvbiIsImF1ZCI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbS9vL29hdXRoMi90b2tlbiIsImV4cCI6MTMyODU1NDM4NSwiaWF0IjoxMzI4NTUwNzg1fQ',
        'eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOlwvXC93d3cuZ29vZ2xlYXBpcy5jb21cL2F1dGhcL3ByZWRpY3Rpb24iLCJhdWQiOiJodHRwczpcL1wvYWNjb3VudHMuZ29vZ2xlLmNvbVwvb1wvb2F1dGgyXC90b2tlbiIsImV4cCI6MTMyODU1NDM4NSwiaWF0IjoxMzI4NTUwNzg1fQ',
    );
    
    foreach($output as $i){
        print_r(base64_decode(strtr($i, '-_', '+/'))) . PHP_EOL;
        print_r(json_decode(base64_decode(strtr($i, '-_', '+/')))) . PHP_EOL;
    }
    

    You’ll see that Google JSON string contains the same values, except that they don’t escape forward slashes:

    Google: https://www.googleapis.com/auth/prediction
    You:    https:\/\/www.googleapis.com\/auth\/prediction
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im using the Google Api PHP v0.5.0(http://code.google.com/p/google-api-php-client/) , to access to Google Analytics, im
I am trying to access google calendar from php program. I am using a
I decided to pull information from Google's Weather API - The code I'm using
I'm trying to use HTTPWebRequest to access a REST service, and am having problems
My web application is based on Google Maps API and I have problems trying
I'm having a strange problem with the Google Calendar API (through PHP with Zend_Gdata.)
With the open source project google-api-ruby-client , I'm trying to run the OAuth 2.0
I have a scripts designed to access an online API (Google Search Appliance), which
I've seen many posts about the Google Geocoding API, described here: http://code.google.com/apis/maps/documentation/geocoding/ but none
Using the google document API, I am creating a document and added access rules.

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.