Google calendar + codeigniter - codeigniter

Can anybody tell me where can I found some info about how integrate the google calendar api on a codeigniter framework.
I follow these steps and everything seems had gone fine, but now I don't know how to continue.
All the files I got following the steps (the json, the library and the quickstart.php) I have them on the library folder of the framework... Is it right??
Is there any tutorial about that??
EDIT
I am making some attempts, but I get some errors... for example I tried to follow the example of this page, it looks simply:
$calendarListEntry = $service->calendarList->get('calendarId');
echo $calendarListEntry->getSummary();
But... where is $service got?? I was looking the examples of the client library, and there is a file call simple-query-php where uses a class called Google_Service_Books, where the object´s name is $service, and I tried to make a mix up from the two sources, and the result is this:
require_once('Google/autoload.php');
$client = new Google_Client();
$client->setApplicationName("My_application_name");
$apiKey = "my-client-secret";
$client->setDeveloperKey($apiKey);
$service = new Google_Service_Books($client);
$calendarListEntry = $service->calendarList->get('calendarId');
echo $calendarListEntry->getSummary();
There is a doubt and an error on execution.
The doubt, in this line: $apiKey = "my-client-secret"; it ask by the API-KEY, but I put the client_secret... is it the same?
The error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Google_Service_Books::$calendarList
Filename: controllers/dashboard.php
Line Number: 17
Fatal error: Call to a member function get() on a non-object in /var/www/html/prototipo/application/controllers/dashboard.php on line 17
How can I get the correct $service object??
Thank you
RE-EDIT
ANSWER ABOUT APIKEY I think it is not the same, I was typing the client secret obtained after create a OAuth 2.0 client ID credential, and now I created a new credential: API KEY-> server key.
I think that now I am getting the right class to obtain the correct $service object, but I found with one more new problem. What I am trying is this:
require_once('Google/autoload.php');
$client = new Google_Client();
$client->setApplicationName("CalendarTest");
$apiKey = "APY-KEY";
$client->setDeveloperKey($apiKey);
$service = new Google_Service_Calendar($client);
$calendarListEntry = $service->calendarList->get('primary');
echo $calendarListEntry->getSummary();
And the result invoking this method on a browser is this:
Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/calendar/v3/users/me/calendarList/calendarId?key=MY-APY-KEY: (401) Login Required' in /home/vendor/google/apiclient/src/Google/Http/REST.php:110 Stack trace: #0 /home/vendor/google/apiclient/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 /home/vendor/google/apiclient/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array) #3 /home/vendor/google/apiclient/src/Google/Http/REST.php(46): Google_Task_Runner->run() #4 /home/vendor/google/apiclient/src/Google/Client.php(593): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request)) #5 /home/vendor/google/apiclient/src/Google/Service/Resource.php(240): Google_Client->execute(Object(Google_Http_Request)) #6 /home/vendor/google/apiclient/src/Go in /home/vendor/google/apiclient/src/Google/Http/REST.php on line 110
It is the same result that if I delete the lines about the applicationName and the apikey. Login Required?? What does it mean??
Thank you.

Followed the page http://www.daimto.com/google-calendar-api-with-php-service-account/ and created code like below which is working without errors.
In this code am getting the public holiday list from google calendar for country India
<?php
require 'vendor/autoload.php';
define('APPLICATION_NAME', 'MY_APPLICATION_NAME');
define('CREDENTIALS_PATH', 'credentials/SERVICE_ACCOUNT.p12');
define('EMAIL_ADDRESS', 'holidays#mycalndear.iam.gserviceaccount.com');
/**
* Returns an authorized API client.
* #return Google_Client the authorized client object
*/
function getClient() {
//below lines can be left as it is
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$key = file_get_contents(CREDENTIALS_PATH);
// separate additional scopes with a comma
$scopes ="https://www.googleapis.com/auth/calendar.readonly";
$cred = new Google_Auth_AssertionCredentials(
EMAIL_ADDRESS,
array($scopes),
$key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
return $client;
}
$client = getClient();
$service = new Google_Service_Calendar($client);
$calendarList = $service->calendarList->listCalendarList();
$calendar_id = "en-us.indian#holiday#group.v.calendar.google.com";
// get events
$events = $service->events->listEvents($calendar_id);
foreach ($events->getItems() as $event) {
echo "Summary : ".$event->getSummary()." status : " . $event->getStatus() . " starts at : " . $event->getStart()->date . " ends at : " . $event->getEnd()->date . " html link : " . $event->getHtmlLink() ."\n";
}

Related

How to retrieve respons status from Street View Image Metadata using guzzle

I am using guzzle to call to Street View Image API from my laravel application. I want to be able to retrieve the status code from my request as explained in the end of the docs.
I specifically want to catch the:
{
"status" : "ZERO_RESULTS"
}
here is my Guzzle code from my controller (am including guzzle correctly in namespace). The address in the get call is generating a "Sorry we have no imagery here":
$client = new Client();
$res = $client->get('https://maps.googleapis.com/maps/api/streetview?size=800x600&location=78.648401,14.194336&key=my-API-key&fov=120&heading=90');
$res->getStatusCode();
dd($res->getBody());
BUT. As u can see in the pic the meta-data is empty. When I dd the $res->getStatusCode(); it gives me a 200.
How do I catch the ZERO_RESULT ?
Sir, please note that there are two different endpoints; one for metadata and one for image retrieval. You only used the image retrieval. Here is an example method checking if a given coordinate has an image
private function coordinateHasImage($coordinate)
{
$client = new Client();
$res = $client->get( 'https://maps.googleapis.com/maps/api/streetview/metadata?size=600x300&location=' . $coordinate . '&fov=90&heading=235&pitch=10&key=YOUR_KEY_HERE');
return json_decode($res->getBody()->getContents())->status == "OK";
}

Laravel: Function name must be a string

I'm currently working on a project. It was all working just fine until i tried to migrate some tables that I edited. I got this error:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Function name must be a string
Since I doesn't directly show me where the error is, I couldn't find it. Last things I changed before I tried to migrate tables:
Migrations
Laravel colletive/html forms
Store method in my controller
As I know, migrations and forms shouldn't be a problem with this error, so here's my controller code:
public function store(Request $request)
{
$user = Auth::user();
$input = $request->all();
if ($file = $request->file('photo_id')){
$name = time().$file->getClientOriginalName();
$file->move('images', $name);
$photo = Photo::create(['file'=>$name]);
$input['photo_id'] = $photo->id;
}
$user->posts()->create($input);
return redirect('/userPanel');
}
If the error isn't even in a controller code, where could it be. Any help appreciated.
I have found out it was because of a very silly mistake, i was calling a variable as a function...
$ownedMacs = intval($data()['owned_mac']);
Changed to
$ownedMacs = intval($data['owned_mac']);
This error message usually appears when we are doing something real stupid! :)
Same issue in Laravel can solve
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Function name must be a string
When you checked on storage/logs/laravel.log
local.ERROR: Function name must be a string {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Function name must be a string at E:\\Project\\workspace\\turttyKidsProject\\app\\Http\\Controllers\\SiteContactController.php:52)
[stacktrace]
Solution
Data field requesting another format but you are trying to save an object.
$objectSave= new ObjectClass;
$objectSave->feild_db = $request->post('request_name');
Check whether you access request with your form submit method. it may be POST or GET

Dynamic callback url laravel

I tried to make my callback url dynamic because I'm configuring socialite in a multi auth system. I tried to use the socialiteproviders/manager as below:
$clientId = env($provider."_client_id");
$clientSecret = env($provider."_client_secret");
$redirectUrl = "the url i want";
$config = new \SocialiteProviders\Manager\Config($clientId,$clientSecret,$redirectUrl);
return Socialite::with($provider)->setConfig($config)->redirect();
but it says:
Call to undefined method Laravel\Socialite\Two\FacebookProvider::setConfig()
when trying to login with facebook.
Can someone please help me? Thank you.
I could reproduce and found a solution. The code you provided was outdated, and I found other instances of it here: https://laravel.io/forum/07-28-2016-dynamic-callback-url-laravel-socialite
By default, Socialite will get the provider config in services.php by passing the $providerName = facebook
So your code now becomes:
// The services.php config will return null, fix it by using: strtoupper()
$clientId = env(strtoupper($provider . "_client_id"));
$clientSecret = env(strtoupper($provider . "_client_secret"));
$redirectUrl = "/the-url-i-want";
// ->redirect() acts as a closure, without it, you'll get an error like:
// "Serialization of 'Closure' is not allowed"
$user = Socialite::with($provider)->redirect();
return redirect()->to($redirectUrl)->with(['user', $user]);
More info on redirecting with session data:
https://laravel.com/docs/6.x/redirects#redirecting-with-flashed-session-data

get product list using soap api magento

I am using Soap Api and want to get product list whose stock is not 0, meaning there is at least 1 inventory(Stock) of the product in magento.
I am using this type of code but it is not working.
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$sessionId = $proxy->login((object)array('username' => 'apiUser', 'apiKey' => 'apiKey'));
$result = $proxy->catalogInventoryStockItemList((object)array('sessionId' => $sessionId->result, 'productIds' => array(1,2)));
var_dump($result->result);
Use the code below, it worked for me:
$proxy = new SoapClient('http://yourstore.com/api/v2_soap/?wsdl');
$sessionId = $proxy->login('apiUserName', 'apiKey');
$result = $proxy->catalogProductList($sessionId);
var_dump($result);
If this did not work for you try to replace the url with the following (add "index.php") http://yourstore.com/index.php/api/v2_soap/?wsdl
Hope this solves your problem!
Try adding the following lines before the code to enable error logging to see what the error is, seeing a blank screen might be because there is an error but you dont see it:
ini_set('display_errors', true);
error_reporting(E_ALL);
Can you also access this URL "yourstore.com/api/v2_soap/?wsdl" or this "yourstore.com/index.php/api/v2_soap/?wsdl" directly in your browser and let me know what you see? you should be able to see an XML document, if there is a setting issue, you will see something like "Invalid service adapter" or somekind of an error message.
use v1 api
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$session = $client->login('apiUser', 'apiKey');
$proxy->call($session, 'catalog_product.info',array(1,2));//productIds

Getting customer telephone & order_id on success page for Send SMS on opencart-2.0.3.1

How do I get customer telephone & order_id on the catalog/controller/checkout/success.php page for Send SMS on opencart-2.0.3.1?
I tried this:
//after this this line: $this->model_account_activity->addActivity('order_guest', $activity_data);}
$orderID = $this->session->data['order_id'];
$msisdn=$this->customer->getTelephone();
$sms ='Congrats! You have successfully made orderID# '.$orderID.' Thank You. #TestSMS';
Showing Error as Follows:
Warning: Illegal string offset 'breadcrumbs'
Notice: Array to string conversion
Warning: Illegal string offset 'breadcrumbs'
Thanks for share your file code here.
You have used a variable $data before your curl requeset, as opencart has global variable $data itself in which all data move from controller to template.
$data=$param.$sms.$sid;
$crl = curl_init();
curl_setopt($crl,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($crl,CURLOPT_SSL_VERIFYHOST,2);
curl_setopt($crl,CURLOPT_URL,$url);
curl_setopt($crl,CURLOPT_HEADER,0);
curl_setopt($crl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($crl,CURLOPT_POST,1);
curl_setopt($crl,CURLOPT_POSTFIELDS,$data);
$response = curl_exec($crl);
curl_close($crl);
Please change the $data variable name with any another variable here & userd the new variable in curl request, or used below code instaed of upper one
$dataNew=$param.$sms.$sid;
$crl = curl_init();
curl_setopt($crl,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($crl,CURLOPT_SSL_VERIFYHOST,2);
curl_setopt($crl,CURLOPT_URL,$url);
curl_setopt($crl,CURLOPT_HEADER,0);
curl_setopt($crl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($crl,CURLOPT_POST,1);
curl_setopt($crl,CURLOPT_POSTFIELDS,$dataNew);
$response = curl_exec($crl);
curl_close($crl);

Resources