I tried to get SharePoint list in php. Below is code
require_once __DIR__ . '\Faker-master\src\autoload.php'; //Faker library (https://github.com/fzaninotto/Faker)
require_once 'lib/SPOClient.php';
$username = 'aaaa.aaa#microsoft.com';
$password = '*******';
$url = "https://microsoft.sharepoint.com";
generateContacts($url,$username,$password);
function generateContacts($url,$username,$password){
$client = new SPOClient($url);
$client->signIn($username,$password);
$list = $client->getList('ClientMaster');
$contactsCount = 120;
for($i = 0; $i < $contactsCount; $i++){
$contactEntry = createContactEntry();
$item = $list->addItem($contactEntry);
print "Contact '{$item->Title}' has been created succesfully.\r\n";
}
}
O/p:
Fatal error: Uncaught exception 'Exception' with message 'Invalid STS request. ' in E:\Apps\xampp\htdocs\ep\lib\SPOClient.php:260 Stack trace: #0 E:\Apps\xampp\htdocs\ep\lib\SPOClient.php(242): SPOClient->processToken('requestToken('ssss.kkkk...', '*****') #2 E:\Apps\xampp\htdocs\ep\listexamples.php(24): SPOClient->signIn('ssss.kkkk...', '******') #3 E:\Apps\xampp\htdocs\ep\listexamples.php(15): generateContacts('https://worldem...', 'sssss.kkk...', '******') #4 {main} thrown in E:\Apps\xampp\htdocs\ep\lib\SPOClient.php on line 260
Related
I want request-response with wsdl in php
But I getting error
"Fatal error: Uncaught SoapFault exception: [HTTP] Unauthorized"
WSDL https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsarizi?wsdl
My code in index.php
$istek = new SoapClient('https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsarizi?wsdl');
$auth = new stdClass();
$auth->Username = '999999';
$auth->Password = '999999testtest';
$header = new SoapHeader('https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsarizi?wsdl', 'AuthHeader', $auth, false);
$istek->__setSoapHeaders($header);
echo "<pre>";
print_r($istek->__getTypes());
echo "</pre>";
echo "<hr /><br /><br /><br />";
$sonuc = $istek->seyahatIzinKontrol(array(
'wsuser' => array(
'kullaniciAdi' => '999999',
'sifre' => '999999testtest')
,
'tcKimlikNo' => '15058023598')
);
if ($sonuc->seyahatIzinKontrol) {
echo 'OK';
}else {
echo 'ERROR';
};
Here is the error I'm getting:
Fatal error: Uncaught SoapFault exception: [HTTP] Unauthorized in C:\xampp\htdocs\index.php:72 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://servis....', 'http://uetds.un...', 1, 0) #1 C:\xampp\htdocs\index.php(72): SoapClient->__call('seyahatIzinKont...', Array) #2 {main} thrown in C:\xampp\htdocs\index.php on line 72
What my error?
I am trying to load email list using oauth 2. Following is my code:
<?php
require_once "vendor/autoload.php";
use src\API\Type;
use garethp\ews\MailAPI as API;
$token='EwA......'; //access token
$api = API::withCallbackToken('outlook.office365.com', $token);
$mail = $api->getMailItems();
foreach ($mail as $email) {
$email = $api->getItem($email->getItemId());
$email_id=$email->getItemId();
$subject = $email->getSubject();
$sender = $email->getSender()->getMailbox()->getEmailAddress();
$body = (string) $email->getBody();
echo $body;
}
but getting response as follows:
Fatal error: Uncaught garethp\ews\API\Exception\UnauthorizedException
in
C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices.php:438
Stack trace: #0
C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices.php(356):
garethp\ews\API\ExchangeWebServices->handleNonSuccessfulResponses(NULL,
401) #1
C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices\MiddlewareFactory.php(57):
garethp\ews\API\ExchangeWebServices->processResponse(NULL) #2
C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices.php(497):
garethp\ews\API\ExchangeWebServices->garethp\ews\API\ExchangeWebServices{closure}(Object(garethp\ews\API\MiddlewareRequest),
Object(Closure)) #3
C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices\MiddlewareFactory.php(66):
garethp\ews\API\ExchangeWebServices->garethp\ews\API{closure}(Object(garethp\ews\API\MiddlewareRequest)) #4 C:\inetpub\wwwroot\bephpforTt in C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices.php
on line 438
Here is my code:
if($approved) {
$payerId = $_GET['PayerID'];
// Get payment_id from database
$paymentId = mysql_query("Select payment_id from transactions_paypal WHERE hash = '".$_SESSION['paypal_hash']."'");
$paymentId = mysql_fetch_array($paymentId);
$payment = Payment::get($paymentId, $apiContext);
echo "<pre>";
var_dump($payment);
echo "</pre>";
die();
}else {
header('Location: ../paypal/cancelled.php');
}
But I get this errors:
Notice: Array to string conversion in
C:\xampp\htdocs\Tipperen\test\PayPal-PHP-SDK\paypal\rest-api-sdk-php\lib\PayPal\Api\Payment.php
on line 322
or
Fatal error: Uncaught exception
'PayPal\Exception\PayPalConnectionException' with message 'Got Http
response code 404 when accessing
https://api.sandbox.paypal.com/v1/payments/payment/Array.' in
C:\xampp\htdocs\Tipperen\test\PayPal-PHP-SDK\paypal\rest-api-sdk-php\lib\PayPal\Core\PayPalHttpConnection.php:159
Stack trace: #0
C:\xampp\htdocs\Tipperen\test\PayPal-PHP-SDK\paypal\rest-api-sdk-php\lib\PayPal\Transport\PayPalRestCall.php(74):
PayPal\Core\PayPalHttpConnection->execute('') #1
C:\xampp\htdocs\Tipperen\test\PayPal-PHP-SDK\paypal\rest-api-sdk-php\lib\PayPal\Common\PayPalResourceModel.php(103):
PayPal\Transport\PayPalRestCall->execute(Array, '/v1/payments/pa...',
'GET', '', NULL) #2
C:\xampp\htdocs\Tipperen\test\PayPal-PHP-SDK\paypal\rest-api-sdk-php\lib\PayPal\Api\Payment.php(328):
PayPal\Common\PayPalResourceModel::executeCall('/v1/payments/pa...',
'GET', '', NULL, Object(PayPal\Rest\ApiContext), NULL) #3
C:\xampp\htdocs\Tipperen\test\paypal\pay.php(20):
PayPal\Api\Payment::get(Array, Object(PayPal\Rest\ApiContext)) in
C:\xampp\htdocs\Tipperen\test\PayPal-PHP-SDK\paypal\rest-api-sdk-php\lib\PayPal\Core\PayPalHttpConnection.php
on line 159
Please help me.
I'm trying to get started with the google SpreadSheet API. I know there are a bunch of other languages but PHP is the only one I'm vaguely competent in. I keep falling at the first hurdle and getting:
Fatal error: Uncaught exception 'Google\Spreadsheet\Exception' in
/Users/djave/Google Drive/Sites/practise/gdata/lib/Google/Spreadsheet/ServiceRequestFactory.php:48
Stack trace: #0 /Users/djave/Google Drive/Sites/practise/gdata/lib/Google/Spreadsheet/SpreadsheetService.php(37):
Google\Spreadsheet\ServiceRequestFactory::getInstance()
#1 /Users/djave/Google Drive/Sites/practise/gdata/index.php(32): Google\Spreadsheet\SpreadsheetService->getSpreadsheets()
#2 {main} thrown in /Users/djave/Google Drive/Sites/practise/gdata/lib/Google/Spreadsheet/ServiceRequestFactory.php on line 48
How this happens:
Step 1 Download and add the folder google-api-php-client
Next, fiddle with the code until it works
set_include_path('lib/');
require_once 'lib/Google/Client.php';
require_once 'lib/Google/Service/Books.php';
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$client->setDeveloperKey("-------------------------------------");
$service = new Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
foreach ($results as $item) {
echo $item['volumeInfo']['title'], "<br /> \n";
}
Result: prints out a list of books
Step 2 Download and install php-google-spreadsheet-client
First off I copy the example exactly below what I have, then include all the right files until it can find everything:
set_include_path('lib/');
require_once 'lib/Google/Client.php';
require_once 'lib/Google/Service/Books.php';
require_once 'lib/Google/Spreadsheet/SpreadsheetService.php';
require_once 'lib/Google/Spreadsheet/ServiceRequestFactory.php';
require_once 'lib/Google/Spreadsheet/Exception.php';
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$client->setDeveloperKey("-------------------------------------");
$service = new Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
foreach ($results as $item) {
echo $item['volumeInfo']['title'], "<br /> \n";
}
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
$spreadsheet = $spreadsheetFeed->getByTitle('MySpreadsheet');
$worksheetFeed = $spreadsheet->getWorksheets();
But I just get
Fatal error: Uncaught exception 'Google\Spreadsheet\Exception' in /Users/djave/Google Drive/Sites/practise/gdata/lib/Google/Spreadsheet/ServiceRequestFactory.php:48 Stack trace: #0 /Users/djave/Google Drive/Sites/practise/gdata/lib/Google/Spreadsheet/SpreadsheetService.php(37): Google\Spreadsheet\ServiceRequestFactory::getInstance() #1 /Users/djave/Google Drive/Sites/practise/gdata/index.php(23): Google\Spreadsheet\SpreadsheetService->getSpreadsheets() #2 {main} thrown in /Users/djave/Google Drive/Sites/practise/gdata/lib/Google/Spreadsheet/ServiceRequestFactory.php on line 48
I'm doing something really stupid, right? Thanks for any help
Looks like you've forgotten to bootstrap the lib first: https://github.com/asimlqt/php-google-spreadsheet-client#bootstrapping
require 'vendor/autoload.php';
use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;
$serviceRequest = new DefaultServiceRequest($accessToken);
ServiceRequestFactory::setInstance($serviceRequest);
Give edit permission to "client_email" field value in client_secret.json file by opening the actual spreadsheet, refer image.
I am using php and mysql. I have to get anlytics data of different sites using google sdk api and most important thing is that I need not to login in api. without login I need go get analytics data.
please have a look below code where I am able to get 'Google_AnalyticsService' object and facing error while getting data.It is saying Login Required...
require 'apigp/Google_Client.php';
require 'apigp/contrib/Google_PlusService.php';
require 'apigp/contrib/Google_AnalyticsService.php';
date_default_timezone_set('UTC');
$date_beforeonemoth = date("Y-m-d", mktime(0,0,0,date("m"),date("d")-30,date("Y")));
$date_today = date("Y-m-d", mktime(0,0,0,date("m"),date("d"),date("Y")));
$google = new Google_Client();
$google->setDeveloperKey('Google AppKey here');
$google->setClientSecret('Google ClientSecretKey here');
$google->setClientId('Google ClientID here');
$analytics = new Google_AnalyticsService($google);
$profileURL="";
$pageName="";
$brandId="";
$sql="select * from profiles where APIType='Google Plus'";
$result=mysql_query($sql);
while($rs = mysql_fetch_assoc($result))
{
$profileURL='https://plus.google.com/105932700878744xxxxxx';
$brandId=4;
$pageName=basename($profileURL);
$accounts = $analytics->management_accounts->listManagementAccounts();
if(isset($accounts['totalResults'])){
if($accounts['totalResults']>0){
$firstAccountId = $accounts['items'][0]['id'];
$webproperties = $analytics->management_webproperties->listManagementWebproperties($firstAccountId);
if(count($webproperties['items'])>0){
$firstWebpropertyId = $webproperties['items'][0]['id'];
$profiles = $analytics->management_profiles->listManagementProfiles($firstAccountId, $firstWebpropertyId);
if (count($profiles['items']) > 0) {
$profileId = $profiles['items'][0]['id'];
$profileId = $pageName;
$results = $analytics->data_ga->get(
'ga:' . $profileId,
$date_beforeonemoth,
$date_today,
'ga:visits,ga:pageviews,ga:pageviewsPerVisit,ga:avgTimeOnPage,ga:visitBounceRate,ga:percentNewVisits,ga:uniquePageviews',
array(
'dimensions' => 'ga:source,ga:keyword,ga:browser,ga:date,ga:month,ga:day,ga:year',
'sort' => '-ga:visits,ga:keyword',
// 'filters' => 'ga:medium==organic',
'max-results' => '25'));
$visits = "";
$unique_visitors = "";
$pageviews = "";
$pages_visit = "";
$avg_visit_duration = "";
$bounce_rate = "";
$new_visits = "";
echo "<br>".$visits = $results['totalsForAllResults']['ga:visits'];
echo "<br>".$unique_visitors = $results['totalsForAllResults']['ga:uniquePageviews'];
echo "<br>".$pageviews = $results['totalsForAllResults']['ga:pageviews'];
$pages_visit = $results['totalsForAllResults']['ga:pageviewsPerVisit'];
$avg_visit_duration = $results['totalsForAllResults']['ga:avgTimeOnPage'];
$bounce_rate = $results['totalsForAllResults']['ga:visitBounceRate'];
$new_visits = $results['totalsForAllResults']['ga:percentNewVisits'];
$profileName = $results['profileInfo']['profileName'];
}else{print"No profiles found for this user.";}
}else{print"No webproperties found for this user.";} //close webproperties result if condition
}else{print"No accounts found for this user.";} //close total result if condition
}
}
Error:
Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/analytics/v3/management/accounts?key=AIzaSyBeh0Aevex7q3iRIY5bV3N9gx0WAkNBMi4: (401) Login Required' in E:\xampp\htdocs\DATAPOINTS\apigp\io\Google_REST.php:66 Stack trace: #0 E:\xampp\htdocs\DATAPOINTS\apigp\io\Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 E:\xampp\htdocs\DATAPOINTS\apigp\service\Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 E:\xampp\htdocs\DATAPOINTS\apigp\contrib\Google_AnalyticsService.php(139): Google_ServiceResource->__call('list', Array) #3 E:\xampp\htdocs\DATAPOINTS\anatest.php(33): Google_ManagementAccountsServiceResource->listManagementAccounts() #4 {main} thrown in E:\xampp\htdocs\DATAPOINTS\apigp\io\Google_REST.php on line 66
How to get analytics data without login in api ?
According to Google, you must send authorization credentials with each API request.
See here: https://developers.google.com/analytics/devguides/reporting/core/v3/#user_reports