The code in PHP:
<?php
require 'C:\inetpub\wwwroot\Imzo.be\vendor\autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=C:\inetpub\wwwroot\Imzo.be\secret\central-eon-267809-2d6dc3c388dc.json');
use Google\Cloud\Translate\V3\TranslationServiceClient;
function translate($text, $to){
$projectId = "central-eon-267809";
$translationClient = new TranslationServiceClient();
$string = $text;
$string = strip_tags(htmlspecialchars_decode($string));
$string = utf8_encode($string);
$content = [$string];
$targetLanguage = $to;
$response = $translationClient->translateText(
$content,
$targetLanguage,
TranslationServiceClient::locationName($projectId, 'global')
);
foreach ($response->getTranslations() as $key => $translation) {
$separator = $key === 2
? '!'
: ', ';
return $translation->getTranslatedText(); //. $separator;
}
}
?>
The Json-file (i'll make a new one when solved):
{
"type": "service_account",
"project_id": "central-eon-267809",
"private_key_id": "2d6dc3c388dc908c8fc440d238f0a9d237d0c2b9",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDPdczc7pvqh14I\nFJee/Ayhygn80nK6dKe8v6JZeMgfUx7e5/ziaV7oDufw/FAtkfRXa6YE7IMnmLeZ\nQ5hv3/PDEZ/Gs4QvBlaIGVAcN2Omi3k3eeC/osc1RzoVm7uG+eW9rjUe/XqtfVfV\nHhpnt5UbRR0uB0m4t/sIikprmS7gSL8ft80M7fYc2f7c9sQgkUlgwbYIogXVbxhl\n1Vym61PikgYnbAksZsHKEvRDdQx/+lzfvggMMeKlxw88DpFTIVyxctz/MkrY4Jid\n67Hj9L4A1Kcw981nDGGEefQ7yj3M2H9MLq6bGZs78Qv/dUi3nwcQaoHxKI592zrd\nfMFb9MLrAgMBAAECggEAILg2CsQ75VCF5Tqw3RtojJ3LrHWuhYy/exaIRESMijA3\nBrX08uqRKYKsVHF0Mx5kDeOa/VzQpKPtP6gNuIX22+sBgDpbhyUglvooYdg0iGr9\nP7bNBRG8Xxaa6Rc04NQJ8WaygcQ9nx4ih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g84v8R9PhnL3Ty6tTZXCAII\nr/kKDFm/VK3aUvpC92m5xfTE\n-----END PRIVATE KEY-----\n",
"client_email": "translate#central-eon-267809.iam.gserviceaccount.com",
"client_id": "100927717394460781967",
"auth_uri": "https://www.googleapis.com/auth/cloud-platform",
"token_uri": "https://www.googleapis.com/auth/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/translate%40central-eon-267809.iam.gserviceaccount.com"
}
The error:
[02-Apr-2021 15:49:52 Europe/Brussels] PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://oauth2.googleapis.com/token` resulted in a `400 Bad Request` response:
{"error":"invalid_scope","error_description":"Invalid OAuth scope or ID token audience provided."}
in C:\inetpub\wwwroot\Imzo.be\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113
Stack trace:
#0 C:\inetpub\wwwroot\Imzo.be\vendor\guzzlehttp\guzzle\src\Middleware.php(69): GuzzleHttp\Exception\RequestException::create()
#1 C:\inetpub\wwwroot\Imzo.be\vendor\guzzlehttp\promises\src\Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp\{closure}()
#2 C:\inetpub\wwwroot\Imzo.be\vendor\guzzlehttp\promises\src\Promise.php(153): GuzzleHttp\Promise\Promise::callHandler()
#3 C:\inetpub\wwwroot\Imzo.be\vendor\guzzlehttp\promises\src\TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 C:\inetpub\wwwroot\Imzo.be\vendor\guzzlehttp\promises\src\Promise.php(248): GuzzleHttp\Promise\TaskQueue->run()
#5 C:\inetpub\wwwroot\Imzo.be\vendor\guzzleh in C:\inetpub\wwwroot\Imzo.be\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113
Does anyone know what is wrong in this?
I think everything is configured correctly in the Google Cloud.
It might be a problem with the auth_uri or token_uri.
Please help.
Related
The code worked correctly on version 7+, however, when the version is downgraded to 6, the function falls with an error.
Code:
<?
define(ZIP_TO_LOCATION_APP, "https://tools.usps.com/tools/app/ziplookup/cityByZip");
function get_location_from_zip($zip_code) {
$client = new GuzzleHttp\Client();
$response = $client->request("POST", ZIP_TO_LOCATION_APP, [
'form_params' => [
'zip' => $zip_code
]
]);
if ($response->getStatusCode() == 200) {
$contents = $response->getBody()->getContents();
$contents = json_decode($contents, true);
$contents["error"] = false;
return $contents;
} else {
return array(
"error" => true
);
}
}
Output:
Fatal error: Uncaught GuzzleHttp\Exception\TooManyRedirectsException: Will not follow more than 5 redirects in C:\OpenServer\domains\job-board.loc\api\classes\composer\vendor\guzzlehttp\guzzle\src\RedirectMiddleware.php:159 Stack trace: #0 C:\OpenServer\domains\job-board.loc\api\classes\composer\vendor\guzzlehttp\guzzle\src\RedirectMiddleware.php(94): GuzzleHttp\RedirectMiddleware->guardMax(Object(GuzzleHttp\Psr7\Request), Array) #1 C:\OpenServer\domains\job-board.loc\api\classes\composer\vendor\guzzlehttp\guzzle\src\RedirectMiddleware.php(72): GuzzleHttp\RedirectMiddleware->checkRedirect(Object(GuzzleHttp\Psr7\Request), Array, Object(GuzzleHttp\Psr7\Response)) #2 C:\OpenServer\domains\job-board.loc\api\classes\composer\vendor\guzzlehttp\promises\src\FulfilledPromise.php(41): GuzzleHttp\RedirectMiddleware->GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response)) #3 C:\OpenServer\domains\job-board.loc\api\classes\composer\vendor\guzzlehttp\promises\src\TaskQueue.php(48): GuzzleHttp\Promise\FulfilledPromise::GuzzleHttp\Promis in C:\OpenServer\domains\job-board.loc\api\classes\composer\vendor\guzzlehttp\guzzle\src\RedirectMiddleware.php on line 159
I tried playing around with the allow_redirects option, this can hide the exception, but it still doesn't return a response.
I want to edit caption of photo, but Im getting error Bad Request: message to edit not found
Code :
<?php
require_once 'Telegram.php';
$telegram = new Telegram('bot:TOken');
$result = $telegram->getData();
$text = $result['message'] ['text'];
$chat_id = $result['message'] ['chat']['id'];
$messageID = $result['message']['message_id'];
$content = array('chat_id' => $chat_id, 'message_id' => $messageID, 'caption' => "wadawd");
// $content = array('chat_id' => $chat_id, 'text' => $messageID);
$telegram->editMessageCaption($content);
Error Log :
============[Date]============
[ 2022-02-28 12:36:58 UTC ]
==========[Response]==========
ok: False
error_code: 400
description: Bad Request: message to edit not found
=========[Sent Data]==========
[ref]
ref.update_id= 3618619
ref.message.message_id= 42
ref.message.from.id= 52868936
ref.message.from.is_bot= false
ref.message.from.first_name= Ramana
ref.message.from.last_name= Owner
ref.message.from.language_code= en
ref.message.chat.id= 52868936
ref.message.chat.first_name= Ramana
ref.message.chat.last_name= Owner
ref.message.chat.type= private
ref.message.date= 1646051816
ref.message.text= esfsef
[ref]
ref.message_id=
ref.caption= wadawd
============[Trace]===========
#0 /home/onbvbrh08q4z/public_html/captionbot/Telegram.php(3228): TelegramErrorLogger::log()
#1 /home/onbvbrh08q4z/public_html/captionbot/Telegram.php(111): Telegram->sendAPIRequest()
#2 /home/onbvbrh08q4z/public_html/captionbot/Telegram.php(1633): Telegram->endpoint()
#3 /home/onbvbrh08q4z/public_html/captionbot/test.php(15): Telegram->editMessageCaption()
#4 {main}
I'm using this github repo https://github.com/Eleirbag89/TelegramBotPHP
Bots (using api.telegram.org) cannot edit messages of posts made before the bot was added to the channel.
Hence, Telegram Bot Api shows you the error "message to edit not found"
I am trying to upload a file in chunks via Dropbox's API for PHP.
This is my code: This gives out the folowing error:
First few chunks are uploaded and then I get this error:-
Fatal error: Uncaught exception 'Dropbox\Exception_NetworkIO' with message 'Erro
r executing HTTP request: Failed to connect to api-content.dropbox.com port 443:
Connection refused' in /home/yashtk1/public_html/dropbox/Dropbox/Curl.php:69
Stack trace:
#0 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(721): Dropbox\Curl->exec
()
#1 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(602): Dropbox\Client->_c
hunkedUpload(Array, '`S\xCDb0\x80`\xA0\xD3\xB7\xEA\x07\xF1\xF7\xB4...')
#2 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(437): Dropbox\Client->ch
unkedUploadContinue('jB2ZQWVyzMQgsX4...', 41943040, '`S\xCDb0\x80`\xA0\xD3\xB7\x
EA\x07\xF1\xF7\xB4...')
#3 /home/yashtk1/public_html/dropbox/Dropbox/RequestUtil.php(278): Dropbox\Clien
t->Dropbox\{closure}()
#4 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(438): Dropbox\RequestUti
l::runWithRetry(3, Object(Closure))
#5 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(381): Dropbox\Client->_u
ploadFileChunked('/ahmd1.zip', Object(Dropbox\WriteMode), Resource i in /home/ya
shtk1/public_html/dropbox/Dropbox/Curl.php on line 69
My script:-
<?php
echo "hi";
set_time_limit(0);
# Include the Dropbox SDK libraries
require_once "Dropbox/autoload.php";
use \Dropbox as dbx;
$appInfo = dbx\AppInfo::loadFromJsonFile("config");
$f = fopen("ahmd1.zip", "rb");
$dbxClient = new dbx\Client("Access code", "PHP-Example/1.0");
$mode = dbx\WriteMode::add();
$chunk = $dbxClient->uploadFileChunked("/ahmd1.zip", $mode, $f);
print_r($chunk);
//uploadFileChunked( string $path, Dropbox\WriteMode $writeMode, resource $inStream, integer|null $numBytes = null, integer|null $chunkSize = null );
fclose($f);
?>
Please can anyone point out the mistake ?
I am working with the UPS api and am having a difficult time debugging. I am getting the following stack trace:
Details
Type: SoapFault
Message: An exception has been raised as a result of client data.
File: /Users/shawn/Documents/work/sites/Wingspan/kaleco/lib/SixString/Utilities/Ups.php
Line: 161
Trace
#0 /Users/shawn/Documents/work/sites/Wingspan/kaleco/lib/SixString/Utilities/Ups.php(161): SoapClient->__soapCall('ProcessShipment', Array)
#1 /Users/shawn/Documents/work/sites/Wingspan/kaleco/routes/ups.php(14): SixString\Utilities\Ups->getShipment()
#2 [internal function]: {closure}()
#3 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Router.php(172): call_user_func_array(Object(Closure), Array)
#4 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Slim.php(1222): Slim\Router->dispatch(Object(Slim\Route))
#5 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Middleware/Flash.php(86): Slim\Slim->call()
#6 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Middleware/MethodOverride.php(94): Slim\Middleware\Flash->call()
#7 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Middleware/SessionCookie.php(116): Slim\Middleware\MethodOverride->call()
#8 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php(67): Slim\Middleware\SessionCookie->call()
#9 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Slim.php(1174): Slim\Middleware\PrettyExceptions->call()
#10 /Users/shawn/Documents/work/sites/Wingspan/kaleco/public/index.php(6): Slim\Slim->run()
#11 {main}
Here is the block of code:
try{
$mode = array('soap_version' => 'SOAP_1_1', 'trace' => 1,'exceptions' => true );
$client = new \SoapClient($wsdl , $mode);
$client->__setLocation($endpointurl);
$header = new \SoapHeader('http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0','UPSSecurity',$this->upss);
$client->__setSoapHeaders($header);
if(strcmp($operation,"ProcessShipment") == 0 ) {
$resp = $client->__soapCall('ProcessShipment',array($this->processShipment()));
echo "Response Status: " . $resp->Response->ResponseStatus->Description ."\n";
//print_r($client->__getLastRequest());
}
else if (strcmp($operation , "ProcessShipConfirm") == 0) {
$resp = $client->__soapCall('ProcessShipConfirm',array($this->processShipConfirm()));
echo "Response Status: " . $resp->Response->ResponseStatus->Description ."\n";
}
else {
$resp = $client->__soapCall('ProcessShipeAccept',array($this->processShipAccept()));
//get status
echo "Response Status: " . $resp->Response->ResponseStatus->Description ."\n";
echo "<pre>";
print_r($resp);
echo "</pre>";
}
}
catch(Exception $ex){
print_r ($ex);
}
Line 161 is in the above code, this is the actual line:
$resp = $client->__soapCall('ProcessShipConfirm',array($this->processShipConfirm()));
I am looking for a way to debug this. It does not appear to be reaching the catch block and I cannot seem to determine the cause of the exception.
Try to catch exception with SoapFault and print its detail property.
try {
$response = $client->$call( $params );
} catch (\SoapFault $fault) {
//trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
var_dump($fault->faultcode);
var_dump($fault->faultstring);
var_dump($fault->detail);
die('Errore chiamata webservice UPS');
}
refer to: http://php.net/manual/en/function.is-soap-fault.php
I don't know the nuances of exception handling in PHP, but Soap exceptions are squirrely little buggers in C# as well. In Visual Studio's debugger, you can get at the details of unhandled exceptions right in the IDE. If you have an option to do this, look for the exception's "detail" XML Element, as this will contain the web service's message telling you what was borked with your request.
As for actually trapping the exception, there's an old but good article by #Jeff Atwood that — though written for (gasp) VB.NET — might still provide some insight into what makes Soap exceptions so, er... slippery: Coding Horror | Throwing better SOAP exceptions
NOTE: For what it's worth, UPS gives this error for bad tracking numbers. Use a good (valid) tracking number and it corrected my issue.
UPS gives this error also for bad ShipFrom/CountryCode or ShipTo/CountryCode in Rates API. e.g. germany can't be rated. This can't found in the UPS dev docs.
I've got a working website, which uses youtube api. Everything was fine but today I noticed I get error while using this api:
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 403 <?xml version='1.0' encoding='UTF-8'?><errors><error><domain>yt:quota</domain><code>too_many_recent_calls</code></error></errors>' in /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php:700 Stack trace: #0 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata.php(221): Zend_Gdata_App->performHttpRequest('GET', 'http://gdata.yo...', Array, NULL, NULL, NULL) #1 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php(861): Zend_Gdata->performHttpRequest('GET', 'http://gdata.yo...', Array) #2 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php(754): Zend_Gdata_App->get('http://gdata.yo...', NULL) #3 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php(205): Zend_Gdata_App->importUrl('http://gdata.yo...', 'Zend_Gdata_YouT...', NULL) #4 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata.php( in /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php on line 700
my code looks somehow like this:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Uri_Http');
$yt = new Zend_Gdata_YouTube();
$query = $yt->newVideoQuery();
$query->setQuery($searchTerms);
$query->setStartIndex($index2);
$query->setMaxResults(10);
$query->setOrderBy($order);
$videoFeed = $yt->getVideoFeed($query);
foreach ($videoFeed as $videoEntry) {
$videoThumbnails = $videoEntry->mediaGroup->thumbnail[0]->url;
$title = $videoEntry->mediaGroup->title;
$vidId = $videoEntry->getVideoId();
$vidDescription = $videoEntry->mediaGroup->description;
$duration = $videoEntry->mediaGroup->duration->seconds;
$rating = round($videoEntry->rating->average,1)." out of 5";
echo "info...";
}
Funny thing is that it sometime works and sometime does not... I don't really know why, any help appreciated, thanks.
As stated in comments, I just had to limit the access and lower the calls. Thanks Slava.