I am just trying to connect my PHP with Google API. My aim is to fetch a particular folder's content and show them as feeds in my site. So for a base I am trying to pull the kind of file of my drive. I am struck. Here is my code.
<?php
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_DriveService.php';
$client = new Google_Client(); $client->setApplicationName("My Application");
$client->setDeveloperKey("<mykey>");
$service = new Google_DriveService($client);
$optParams = array('fields' => 'kind'); $results = $service->files->listFiles($optParams);
foreach ($results['files'] as $item) {
print($item['kind'].'<br>');
}
?>
When I execute this, I get the following error,
Fatal error: Uncaught exception 'Google_ServiceException' with message
'Error calling GET
https://www.googleapis.com/drive/v2/files?fields=kind&key=:
(403) Insufficient permissions for this file' in
C:\xampp\htdocs\ccl\gdapi\google-api-php-client\src\io\Google_REST.php:66
Stack trace: #0
C:\xampp\htdocs\ccl\gdapi\google-api-php-client\src\io\Google_REST.php(36):
Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1
C:\xampp\htdocs\ccl\gdapi\google-api-php-client\src\service\Google_ServiceResource.php(177):
Google_REST::execute(Object(Google_HttpRequest)) #2
C:\xampp\htdocs\ccl\gdapi\google-api-php-client\src\contrib\Google_DriveService.php(465):
Google_ServiceResource->__call('list', Array) #3
C:\xampp\htdocs\ccl\gdapi\google-api-php-client\test.php(12):
Google_FilesServiceResource->listFiles(Array) #4 {main} thrown in
C:\xampp\htdocs\ccl\gdapi\google-api-php-client\src\io\Google_REST.php
on line 66
I gave proper key. Kindly help me. Thank you
Related
I started with facebook business sdk for php. Was following this doc: https://developers.facebook.com/docs/business-sdk/getting-started/
installed without trouble, then tried testing as they instructed,
created src/test.php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
$app_id = "{app-id}";
$app_secret = "{appsecret}";
$access_token = "{access-token}";
$account_id = "act_{{adaccount-id}}";
Api::init($app_id, $app_secret, $access_token);
$account = new AdAccount($account_id);
$cursor = $account->getCampaigns();
// Loop over objects
foreach ($cursor as $campaign) {
echo $campaign->{CampaignFields::NAME}.PHP_EOL;
}
filled in the required values. and ran the file. Getting this:
FacebookAds\CrashReporter : Enabled
FacebookAds\CrashReporter : Exception detected!
FacebookAds\CrashReporter : Successfully sent report
Fatal error: Uncaught FacebookAds\Http\Exception\AuthorizationException: Invalid OAuth access token. in C:\laragon\www\testPro\vendor\facebook\php-business-sdk\src\FacebookAds\Http\Exception\RequestException.php:174
Stack trace:
#0 C:\laragon\www\testPro\vendor\facebook\php-business-sdk\src\FacebookAds\Http\Client.php(215): FacebookAds\Http\Exception\RequestException::create(Object(FacebookAds\Http\Response))
#1 C:\laragon\www\testPro\vendor\facebook\php-business-sdk\src\FacebookAds\Http\Request.php(286): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request))
#2 C:\laragon\www\testPro\vendor\facebook\php-business-sdk\src\FacebookAds\Api.php(165): FacebookAds\Http\Request->execute()
#3 C:\laragon\www\testPro\vendor\facebook\php-business-sdk\src\FacebookAds\Api.php(214): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request))
#4 C:\laragon\www\testPro\vendor\facebook\php-business-sdk\src\FacebookAds\ApiRequest.php(187): FacebookAds\Api->call('/act_3667840345...', 'GET', Array, Array)
#5 in C:\laragon\www\testPro\vendor\facebook\php-business-sdk\src\FacebookAds\Http\Exception\RequestException.php on line 174
Not sure what I am doing wrong. Didnt find much by searching. Can anyone please help?
The error you get is pretty explicit: "Invalid OAuth access token"
you can check the token you supplied using Facebook's token-debbuger # https://developers.facebook.com/tools/debug/accesstoken/
most probably you are missing the "ads_management" permission.
I've this code wishing to fetch google mybusiness revies :
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . realpath($_SERVER["DOCUMENT_ROOT"]) . '/google-api/account-service-mybusiness.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes("https://www.googleapis.com/auth/plus.business.manage");
$client->setIncludeGrantedScopes(true);
$user_to_impersonate = "xxxxxx#gmail.com";
$client->setSubject($user_to_impersonate);
$client->authorize();
$locationName = "accounts/xxxxxxxxxx/locations/xxxxxxxxxx";
$myBusinessService = new Google_Service_Mybusiness($client);
$reviews = $myBusinessService->accounts_locations_reviews;
but when I try to fecth reviews I have this FATAL ERROR :
Fatal error: Uncaught Google_Service_Exception: { "error":
"unauthorized_client", "error_description": "Client is unauthorized to
retrieve access tokens using this method." } in
/web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Http/REST.php:118
Stack trace: #0
/web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Http/REST.php(94):
Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response),
Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1
/web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Task/Runner.php(176):
Google_Http_REST::doExecute(Object(GuzzleHttp\Client),
Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2
/web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Http/REST.php(58):
Google_Task_Runner->run() #3
/web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Client.php(798):
Google_Http_REST::execute(Object(Guzzl in
/web/htdocs/www.locandadalmoccia.it/home/google-api/vendor/google/apiclient/src/Google/Http/REST.php
on line 118
Can somneone help me to solve please?
it have been 4 hours trying to troubleshoot this problem,it always return with (403) User does not have an AdSense account , I am trying to get report of my adsense on my website,
Ps:it's server to server connection
require_once realpath(dirname(__FILE__) . '/../src/Google/autoload.php');
require_once '../src/Google/Client.php';
require_once '../src/Google/Service/AdSense.php';
$client_email = 'xxx#xxx-1220.iam.gserviceaccount.com';
$private_key = file_get_contents('adsense-xxxxx.p12');
$scopes = array('https://www.googleapis.com/auth/adsense.readonly');
$credentials = new Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key,
'notasecret'
);
$client = new Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$service = new Google_Service_AdSense($client);
Error Log:
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/adsense/v1.4/accounts?maxResults=50: (403) User does not have an AdSense account.' in /var/www/geturl/ad/src/Google/Http/REST.php:110
#0 /var/www/geturl/ad/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client))
#1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request))
#2 /var/www/geturl/ad/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array)
#3 /var/www/geturl/ad/src/Google/Http/REST.php(46): Google_Task_Runner->run()
#4 /var/www/geturl/ad/src/Google/Client.php(593): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#5 /var/www/geturl/ad/src/Google/Service/Resource.php(240): Google_Client->execute(Object(Google_Http_Request))
#6 /var/www/geturl/ad/src/Google/Service/AdSense.php(1106): Google_Service_Resource->call('list', Array, 'Google_Servic in /var/www/geturl/ad/src/Google/Http/REST.php on line 110
Did you wait for 24 hours after enabling the api?
Try testing the account to make sure that it works outside of code. Use the APIs explorer:
https://developers.google.com/adsense/management/v1.4/reference/accounts/list#try-it
Authenticate and try to fetch accounts list.
If that works, make sure you are connecting to the API using that account credentials.
Edit:
Perhaps one of these can help:
https://github.com/googleads/googleads-adsense-examples/tree/master/php-clientlib-1.x/v1.x
https://developers.google.com/adsense/management/libraries
http://www.binarytides.com/php-get-adsense-earnings-and-reports/
I am trying to utilize in php uploading a file using box view api. I am using the library from box-view-api GitHub
Here is my code:
<?php
require_once('repository_fns.php');
require 'lib/box-view-api.php';
require 'lib/box-view-document.php';
session_start();
$objid=$_GET['objid'];
$object_general=get_obj_general($objid);
$object_rights=get_obj_rights($objid);
$object_lifecycle=get_obj_lifecycle($objid);
$object_tech=get_obj_tech($objid);
do_html_header('', 'browse.css');
display_object_metadata($object_general, $object_rights, $object_lifecycle, $object_tech);
$api_key = 'MY_KEY';
$box = new Box_View_API($api_key);
$doc = new Box_View_Document(array(
'name' => 'Geology of Canada',
'file_path' => '/uploads/Geology of Canada.docx',
));
$box->upload($doc);
display_file_page();
do_html_footer();
?>
But why am I getting an error message:
Fatal error: Uncaught exception 'Box_View_Exception' with message 'couldn't open file "/uploads/Geology of Canada.docx"' in /home/ychenlucs15/public_html/lib/box-view-api.php:241 Stack trace: #0 /home/ychenlucs15/public_html/lib/box-view-api.php(456): Box_View_API->httpRequest(Array) #1 /home/ychenlucs15/public_html/show_object.php(28): Box_View_API->upload(Object(Box_View_Document)) #2 {main} thrown in /home/ychenlucs15/public_html/lib/box-view-api.php on line 241
Can someone show me how to implement it correctly with php? Thank you in advance.
I have PHP code that is managing mailing lists using the Provisioning API. Visitors are able to opt in or out of the mailing list via a web form. It has been working for ~6 months and stopped working 10/1/2013.
I am using this code for testing:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Gapps');
$service = Zend_Gdata_Gapps::AUTH_SERVICE_NAME ;
$username = 'my_username';
$password = 'my_password';
$domain = 'my_domain';
$email = 'test-email#domain.com';
$email_list = 'test-list';
$client = Zend_Gdata_ClientLogin::getHttpClient($username, $password, $service);
$gdata = new Zend_Gdata_Gapps($client, $domain);
$gdata->addRecipientToEmailList($email, $email_list);
I'm receiving the following error message:
PHP Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400
Invalid request URI' in /usr/share/php/Zend/Gdata/App.php:716\nStack trace:
#0 /usr/share/php/Zend/Gdata.php(219): Zend_Gdata_App->performHttpRequest('POST', 'https://apps-ap...', Array, '<atom:entry xml...', 'application/ato...', NULL)
#1 /usr/share/php/Zend/Gdata/App.php(908): Zend_Gdata->performHttpRequest('POST', 'https://apps-ap...', Array, '<atom:entry xml...', 'application/ato...')
#2 /usr/share/php/Zend/Gdata/Gapps.php(247): Zend_Gdata_App->post(Object(Zend_Gdata_Gapps_EmailListRecipientEntry), 'https://apps-ap...', NULL, NULL, Array)
#3 /usr/share/php/Zend/Gdata/App.php(983): Zend_Gdata_Gapps->post(Object(Zend_Gdata_Gapps_EmailListRecipientEntry), 'https://apps-ap...', NULL, NULL, Array)
#4 /usr/share/php/Zend/Gdata/Gapps.php(840): Zend_Gdata_App->insertEntry(Object(Zend_Gdata_Gapps_EmailListRecipientEntry), 'https://apps-ap...', 'Zend_Gdata_Gapp...')
#5 /usr/share/php/Zend/Gdata/Gapps.php(1625): Zend_G in /usr/share/php/Zend/Gdata/App.php on line 716
Can anyone tell me what happened? And what I need to do to get this working again?
Thanks,
B
Google completely remove support for emaillists. Use groups instead lists.
Example:
instead $gdata->addRecipientToEmailList($email, $email_list)
use $gdata->addMemberToGroup($email, $group_name)
deleteEmailList -> deleteGroup
createEmailList -> createGroup
getEmailListRecipientFeed -> retrieveAllMembers
See full syntax in Zend docs:
http://framework.zend.com/manual/1.12/en/zend.gdata.gapps.html