This is my first attempt to use the Google API, so I'm probably missing something ridiculously simple.
My API access has been turned on, I've enabled all the web based settings I could find for this feature, setup the Simple API Access and Client ID for web applications, etc.
I'm using the PHP library Google provide here: http://code.google.com/p/google-api-php-client/
As my code wasn't working, I defaulted to their sample code as getting that working usually solves my problems. I've copied their code below:
require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_TranslateService.php';
$client = new Google_Client();
$client->setApplicationName('Translation tool');
// Visit https://code.google.com/apis/console?api=translate to generate your
// client id, client secret, and to register your redirect uri.
$client->setDeveloperKey('XXXXXXXXXXXXXXXX');
$service = new Google_TranslateService($client);
$langs = $service->languages->listLanguages();
print "<h1>Languages</h1><pre>" . print_r($langs, true) . "</pre>";
$translations = $service->translations->listTranslations('Hello', 'hi');
print "<h1>Translations</h1><pre>" . print_r($translations, true) . "</pre>";
I have:
checked the developer key, which is the API key
checked the allowed referers
Set the referers to include .DOMAIN.com/
Set the referers to include the IP address
Tried including the OAuth2 client id, secret, etc
None of these have worked. The error I'm getting in full is as follows:
Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/language/translate/v2/languages?key=XXXXXXXXXXXXXXXX: (403) Access Not Configured' in /home/google-api-php-client/src/io/Google_REST.php:66 Stack trace: #0 /home/google-api-php-client/src/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 /home/google-api-php-client/src/service/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 /home/google-api-php-client/src/contrib/Google_TranslateService.php(39): Google_ServiceResource->__call('list', Array) #3 /home/google-api-php-client/examples/translate/simple.php(13): Google_LanguagesServiceResource->listLanguages() #4 {main} thrown in /home/google-api-php-client/src/io/Google_REST.php on line 66
I'm loosing the will to code with something that should be much more straight forward. Any advice to what might be the problem?
That 403 error is almost certainly related to the Simple API Key. If for example it was a usage restriction the message would say that so....
Double check and make sure you are using the Simple API key listed for server access and have it set to any IP. Specific IP should work but it may depend on how your server is set up.
You may even want to generate a new key just to make sure the one you have is valid. Specific IP would be best in the long run.
Just did the same thing working with the Custom Search API, had the browser key entered and it caused a big dent in the wall as I banged my head into it. . You Shouldn't need any of the OAuth settings just to get the basics working.
i had the same problem but with the analytics api. In my case i listed the ip of the server in the allowed ip addresses.
So when i removed all ip addresses from the google api's console allowed ip addresses then it started working.
Related
I am trying to set up Oauth with the YouTube Data API. I had a Laravel app which has Socialite set up. Out of the box YouTube isn't set up with this but I saw that there is a provider for YouTube here:
https://socialiteproviders.netlify.app/providers/you-tube.html
I have done all of the steps outlined on the page along with all routes that I need. I have also done the Oauth set up on Google Developer Console and got the client ID/secret key and set the callback.
When I use the login URL it works where I'm redirected for login with Google. The problem comes when the callback URL is reached. I get the error:
ErrorException
Undefined index: items
This occurs on the provider callback function which has the code:
$user = Socialite::driver('youtube')->user();
I have tried using stateless:
$user = Socialite::driver('youtube')->stateless()->user();
But get the same error. All caches have been cleared. I am pretty sure that the setup was done correctly as I'm also using the Twitch provider from https://socialiteproviders.netlify.app/providers/twitch.html which the setup was similar and it works correctly.
Please can anyone advise? Thanks.
Try selecting the fields you want to access first:
$user = Socialite::driver('youtube')->fields([
'items'
])->user();
I'm facing the same issue. Is it possible that the API has changed? If I take a look at the raw response there
I also stumbled onto this issue:
When I tested it, I did not got the error, but my colleague did so I figured it had something to do with the account that tried to connect.
I changed my approach from:
$user = Socialite::driver('youtube')->stateless()->user();
And just received tokens by doing this:
$socialite = Socialite::driver('youtube');
$code = $request->input('code');
$response = $socialite->getAccessTokenResponse($code);
$response will contain an array of tokens. I used these tokens to connect it to an existing user in my database.
I don't know if this is the solution for your workflow, but it is a way to get around the mysterious error.
The issue is due to YouTube no longer automatically creating a channel for your google/gmail account like it did in the past. This results in responses completely missing an items array.
if you dd($response->getBody()->getContents()) the response for an account that throws an error you'll see this.
I've made a pull request for this here. https://github.com/SocialiteProviders/YouTube/pull/8
The Paysafe API was working perfectly fine in localhost, I was able to complete payment to Netbanx. I started to integrate the system on the website. I have a page for billing information, then a page for card payment where I use paysafe.js to create a token.
Then, I use PHP to get response from the server. This works in local. But online, this last part where I try to settle a payment, I get an error 500. I think it could be because the server is not using HTTPS. I want to know if it's possible that the error 500 is coming from the fact we don't have HTTPS or if it's something else?
P.S: It's complicated to access to the server because of bureaucracy, I don't want to make all the process if it's sure it's not that!
Thank you!
P.S.: I also tried using curl instead, and the response was bool(false).
require_once("config.php");
use Paysafe\Environment;
use Paysafe\PaysafeApiClient;
use Paysafe\CardPaymentService;
use Paysafe\CardPayments\Authorization;
$client = new PaysafeApiClient($paysafeApiKeyId, $paysafeApiKeySecret, Environment::TEST, $paysafeAccountNumber);
$info = new Authorization(array(
//PAYMENT ARRAY (Getting POST variable from previous page)
));
$response = $client->cardPaymentService()->authorize($info);
$statut = $response->status;
That Environment::TEST obviously does not match the production environment (or host-name).
Just enable PHP error reporting for your IP only, in order not to possibly leak any details.
Also check the console there (if any), if that host if even authorized to access the API.
I mean, HTTP500 is an error description just alike "it does not work".
I am using https://twitteroauth.com/ in my some PHP pages. I want to get user access token and access secret token. I got my answer on this page: How to get user Access Token and Access Secret with the Twitter API using php
After replacing my consumer key and secret consumer key on both pages. I upload it on my server but then I got the following error when I open twitter-go.php
Fatal error: Uncaught exception `'Abraham\TwitterOAuth\TwitterOAuthException'` with message
'<?xml version="1.0" encoding="UTF-8"?>
<hash>
<error>Desktop applications only support the oauth_callback value 'oob'</error>
<request>/oauth/request_token</request>
</hash> '
in `/home/mediahyp/public_html/tweetme/twitteroauth/src/TwitterOAuth.php:138`
Stack trace:
#0 /home/mediahyp/public_html/tweetme/twitter-go.php(13): Abraham\TwitterOAuth\TwitterOAuth->oauth('oauth/request_t...', Array)
#1 {main} thrown in /home/mediahyp/public_html/tweetme/twitteroauth/src/TwitterOAuth.php on line 138
Can anyone tell me what is this error about? Am I missing something or something else.
https://twittercommunity.com/t/desktop-applications-only-support-the-oauth-callback-value-oob-oauth-request-token/252/2
The new interface simplifies this: if you provide a placeholder callback URL in the field for it in your application detail screen, it allows you to use dynamic callbacks. So just go ahead and put a placeholder in there (doesn't have to be the actual dynamic/runtime callback you use) and you'll be able to use other forms of auth.
When no placeholder is presented, the application is locked to OOB mode.
I am doing Language translation using Google Translater API.
Sometimes I am getting following error.
Fatal error: Uncaught GTranslateException: [0]: Unable to perform Translation:Suspected Terms of Service Abuse. Please see http://code.google.com/apis/errors thrown in C:\xampp\htdocs\MyProjectName\public\function\GTranslate.php on line 263
Can anybody help me to fix this problem.
Thanks in advance.
Kanji.
Sign up for google API Key at https://code.google.com/apis/console/ as mentioned earlier.
require_once("GTranslate.php");
try{
$gt = new Gtranslate();
$gt->setApiKey('YOUR_GOOGLE_API_KEY');
$gt->setUserIp($_SERVER['REMOTE_ADDR']);
echo $gt->english_to_german("hello world");
} catch (GTranslateException $ge)
{
echo $ge->getMessage();
}
Also consider to provide user IP address. This also can increase your daily limit.
Sign up for a Google API key at https://code.google.com/apis/console/ and activate the Google Translate API. Use the provided key in your project.
From the Google API Console page, follow on the traffic controls link on the left, then click the Configure Traffic Controls button. Increase the characters/second/user for Google Translate to something much larger than the default 100. Keep in mind you have a limit of 100,000 characters total per day.
Edit: as mentioned in my comment, this is how you would set the API key.
$apikey = 'xyz123';
$gt = new Gtranslate();
$gt->setApiKey($apikey);
I try to get the Live Delegated Authentication to work for the purpose of reading the email addresses.
I am doing this in PHP with the help of the windowslivelogin library. The problem is that I get an error.
I'm not sure what I'm doing wrong, i registered my application on the Azure webpage and got the appid and the secret into the code. This is what i use to initialize the Live Library :
$o = new WindowsLiveLogin();
$o->setAppId('000000004801B670');
$o->setSecret('secret');
$o->setSecurityAlgorithm('wsignin1.0');
$o->setDebug(true);
$o->setPolicyUrl('http://www.google.com/aides.html');
$o->setReturnUrl("http://michaelp.dev.gamepoint.net/framework/mainsite/contactimporter/?service=live");
return $o;
Then I call
$this->LiveLibrary->getLoginUrl()
And after I Login in to Live, it posts 2 things back, $_POST['stoken'] and $_POST['action'].
As soon as I call
$this->LiveLibrary->processLogin($_REQUEST);
It fails and gives back an error that the token is invalid.
I tried getting Consent straight away by making redirecting to
$this->LiveLibrary->getConsentUrl("Contacts.View");
But that gives an 3007 error and says that it cant share the information
According to MS this means the following :
3007
Consent Service API failed in the <method name> method. The application verifier is invalid.
The offer security level requires that a valid application verifier be passed with the request.
I am using the following URL, generated by the library
https://consent.live.com/Delegation.aspx?ps=Contacts.Invite&ru=http%3A%2F%2Fmichaelp.dev.gamepoint.net%2Fframework%2Fmainsite%2Fcontactimporter%2F%3Fservice%3Dlive&pl=http%3A%2F%2Fwww.google.com%2Faides.html&app=appid%3D000000004801B670%26ts%3D1251722931%26sig%3DD2gkM%252F%252FwlRXXfS64NMrV%252Bkt50v6dAOcESblfRk7j%252FUE%253D
I don't understand most of the documentation Microsoft has on this thing, I think its really unclear and chaotic. Also the Sample I tried doesn't work. I get an error message, it can't validate/decode the token. Same I get when I try the processLogin().
Thanks in Advance,
Michael