1

In the official docs for the Google API and OAuth, it has you download a .json file that includes things like clientid, secret, redirect etc. Then it has you build your Google Client like this (I'm using PHP and offline access to interface with the Youtube API):

$client = new Google_Client();
$client->setAuthConfig('client_secrets.json');
$client->setAccessType("offline");        // offline access

However, I've seen examples that allow you to define this information within PHP and set them on the object individually, instead of via the setAuthConfig .json file inclusion. In my case, that's what I want to do so I can have better control over my redirect url and allow storage of my clientid and secret within my settings forms/database. The examples I've seen look like this:

$client = new Google_Client();
$client->setClientId($clientid);
$client->setClientSecret($secret);
$client->setAccessType("offline");
$client->setRedirectUri($redirect);

Are both of these methods valid ways to define the Oauth Google Client in the current (v3) Google API and Oauth?

Feature
  • 163
  • 1
  • 1
  • 6
  • AFAIK, the first one is the support flow in the documents. But you could also try the second code. In the [Creating a Google API Console project and client ID](https://developers.google.com/identity/sign-in/web/devconsole-project) and [CodePen sample](http://codepen.io/gtex/pen/MwJggg.html), it follows the second code. Hope this helps. – Mr.Rebot Mar 26 '17 at 08:18
  • I don't think either is specific to a single google service (ie. docs vs youtube, etc) if that's what you're saying. I think "oauth is oauth", so the same approach works across the api for authentication...although maybe I'm misunderstanding? – Feature Mar 26 '17 at 12:09
  • Yeah you are correct, what I am saying is that the first authentication code that you've provided is currently used in most API quickstart (I'm also using this). I've haven't tried using the second auth code you've provided. I'll try it and check its behavior. – Mr.Rebot Mar 26 '17 at 22:49
  • Thanks. It currently seems to work, but I"m having other issues that (I think) are unrelated. So this post is simply a clarification that this won't cause any unintended problems by building the Google object this way. – Feature Mar 27 '17 at 11:55

0 Answers0