I want to fetch Google contacts for users and create logs of new and updated contacts via a PHP script. Can someone please guide me on how to proceed?
I have implemented the same kind of service for calendar events using 0Auth2.0, but for contacts I didn't find any API in the Google PHP client libraries.
The problem is in the example, it seems that the json encoder does the mess.
One of the developers wrote how to achive email address on this link
http://pastebin.com/kAYT5Jng
You can see part of the discusion right here
Have you tried this project
https://github.com/rapidwebltd/php-google-contacts-v3-api
Fetching all the contacts :
$contacts = rapidweb\googlecontacts\factories\ContactFactory::getAll();
var_dump($contacts);
create new contact
$name = "Frodo Baggins";
$phoneNumber = "06439111222";
$emailAddress = "frodo#example.com";
$note = "Note for example";
$newContact = rapidweb\googlecontacts\factories\ContactFactory::create($name, $phoneNumber, $emailAddress, $note);
Related
Issue
I'm trying to build a little script PHP to integrate with the Microsoft Graph API.
I have an admin account in Azure, and have set up a new app through the portal. I've downloaded and installed the PHP SDK, and have managed to set everything up so that I can get a user successfully.
However, POSTing a new user returns me a 400 bad request:
$newUser = new User();
$newUser->setAccountEnabled(true);
$newUser->setGivenName('name');
$newUser->setSurname('surname');
$newUser->setUserPrincipalName('email#dot.com');
$password = new PasswordProfile();
$password->setPassword("pwd");
$password->setForceChangePasswordNextSignIn(false);
$newUser->setPasswordProfile($password);
$identities = new ObjectIdentity();
$identities->setSignInType("emailAddress");
$identities->setIssuer("a tenantId");
$identities->setIssuerAssignedId("email#dot.com");
$newUser->setIdentities($identities);
$user = $this->graph->createRequest('POST', '/users')
->attachBody($newUser)
->setReturnType(Model\User::class)
->execute();
Returns:
{"error":{"code":"BadRequest","message":"Property identities in payload has a value that does not match schema.","innerError":{"date":"2021-11-15T15:26:24","request-id":"an id","client-request-id":"an id"}}}
How can I solve this issue?
Thanks for any help.
Update
I have found a solution for this problem (obviously, is temporary).
The section "identities" must be set as an array (in JSON) like in this example
"identities": [
{
"signInType": "emailAddress",
"issuer": "contoso.onmicrosoft.com",
"issuerAssignedId": "jsmith#yahoo.com"
}
]
Probably, the PHP code above not set the section "identities" as an array.
Now, I send directly a JSON with the section "identities" as an array but I would like to use the PHP code above.
How can I transform the PHP code above to pass "identities" as an array like in the JSON example?
Thanks again.
Try creating an array and adding the identities on there like. This will add the identities property as an array of Model\ObjectIdentity()
...
$identities = [];
$identity = new Model\ObjectIdentity();
$identity->setSignInType("type");
$identity->setIssuer("issuer");
$identity->setIssuerAssignedId("issure-assigned-id");
array_push($identities, $identity);
$newUser->setIdentities($identities);
...
Good day,
Im creating reminder app that calls a number in certain time, currently I was using an uploaded mp3 file on my server:
here the code:
$sid = "ACxxxxxxxxxx";
$token = "2xxxxxxxxx";
$client = new Client($sid, $token);
$call = $client->calls->create(
"$phone_number_to","$phone_number_from",
array("url" =>
"https://xxxxx.com/asset/mp3/reminder.mp3")
);
$csid = $call->sid;
the above code works, but now I wanted to use the text to speech feature on twilio to have a more customized voicemail per reminder..
how do I do this using $client-> api? Im not really familiar on how TwiML works though, maybe thats why im confused.
thanks!
You change this line of your current code "url" => "https://xxxxx.com/asset/mp3/reminder.mp3" so that the URL points at the url hosting the script you want to use to generate your dynamic TwiML.
Then use the php TwiML library to generate the TwiML, it's pretty straightforward. We have a database with all out customers details in, I use code something along these lines to get their details based on caller ID and have Twilio greet them by first name:
$booked = SELECT * FROM table WHERE phone = $caller;
$name = explode(" ", $booked->name);
$firstname = $name[0];
$response->say("Hello $firstname. Thanks for calling......");
It's ok but it's a bit robotic. We ended up extracting the 50 most common first names from the database and having a voiceover artist record greetings for each one. For callers with one of those 50 names we serve a specific mp3 file, everyone else gets the robot.
I'm using https://github.com/jamesiarmes/php-ews for Exchange Web Services and I'm having a problem adding a contact for an account.
When I login using my impersonation details:
$ews = new ExchangeWebServices($this->server_address, $this->server_username, $this->server_password);
I want to create a new contact, e.g.:
$request = new EWSType_CreateItemType();
$contact = new EWSType_ContactItemType();
$contact->Initials = $this->relation->initials;
$contact->GivenName = $this->relation->first_name;
$contact->MiddleName = $this->relation->insertion;
$contact->Surname = $this->relation->last_name;
$request->Items->Contact[] = $contact;
$result = $ews->CreateItem($request);
I want to add this contact to a account that exists in my impersonation account list.
I want to avoid directly login in as an exchange user like:
$ews = new ExchangeWebServices($this->server_address, 'some#outlook.account', 'somepassword');
Is this possible? How would I achieve such a thing? Thanks for reading!
I'd suggest you most away from james's php-ews, it's unmaintained and doesn't follow any of the PSR's. I'd suggest you take a look at my own fork, garethp/php-ews. Creating a contact would be rather similar, but impersonation is made easy by my fork (example here) and if that's not working for you, you can always drop me a Github issue and I'll try to help out
I've been taking a look at the Google API PHP Client and would like to use it to add rows to a Google Sheet. From the code, it looks like one would use this method:
public function insert($fileId, Google_Service_Drive_Property $postBody, $optParams = array())
{
$params = array('fileId' => $fileId, 'postBody' => $postBody);
$params = array_merge($params, $optParams);
return $this->call('insert', array($params), "Google_Service_Drive_Property");
}
but I can't really tell what the parameters would be. Am I heading in the right direction? Also, not quite sure on how to connect to a specific Sheet. Please advise.
Thanks!
Use Google sheets class from zend framework 1.12. They have very nicely coded library for Google Spreadsheets
https://github.com/zendframework/zf1/tree/master/library/Zend/Gdata/Spreadsheets
I figured out how to work this and wanted to share with you guys. As I stated in a comment, I did not think using Zend's GData class was a good way for me since it's very dependent on other classes throughout the framework, thus being too heavy.
So I ended up using this Spreadsheet Client on top of Google's API. Google's API is used to authenticate my service, then I start calling the Spreadsheet Client library afterwards.
After spending over a day of Googling for various problems I had for the authentication process, here's what I did to make things work:
Created a new project for Google API here
Clicked "APIs" menu on the left side under "APIs & Auth"
Searched the Drive API and enabled it (can't remember if it was necessary)
Clicked the "Credentials" menu on the left
Clicked "Create new Client ID" button under OAuth
Selected "Service Account"
After info showed & json downloaded (not needed), I clicked "Generate new P12 Key" button
I saved the p12 file somewhere I could access it through PHP
Then in the code, I added the following lines:
$email = 'somethingsomethingblahblah#developer.gserviceaccount.com';
$CLIENT_ID = $email;
$SERVICE_ACCOUNT_NAME = $email;
$KEY_FILE = 'path/to/p12/file';
$SPREADSHEETS_SCOPE = 'https://spreadsheets.google.com/feeds';
$key = file_get_contents($KEY_FILE);
$auth = new Google_Auth_AssertionCredentials(
$SERVICE_ACCOUNT_NAME,
array($SPREADSHEETS_SCOPE),
$key
);
$client = new Google_Client();
$client->setScopes(array($SPREADSHEETS_SCOPE));
$client->setAssertionCredentials($auth);
$client->getAuth()->refreshTokenWithAssertion();
$client->setClientId($CLIENT_ID);
$accessToken = $client->getAccessToken();
Also, I had to make sure I:
Shared my spreadsheet specifically with the email address on my service account in the code above
Synced my server's time (I'm running Vagrant CentOS so it's slightly different)
I believe you can run this code with other services beyond Spreadsheets, such as Youtube, Analytics, etc., but you will need to get the correct scope link (see $SPREADSHEETS_SCOPE above). Remember, this is only when using the Service Account on the Google Console, which means you are programmatically getting data from your code. If you are looking to have others users sign in using the API, then it's different.
I used google api to fetch contacts of google account. The code that I used is http://code.google.com/p/google-api-php-client/source/browse/trunk/examples/contacts/simple.php
But when I run the code by applying my credential, it gives me the contacts but just their name. I want the contacts email address.
I always use this to fetch gmail contacts.
http://contactsimporter.com/address-book-importer-demo.html
Hope you will like this too.
It authenticates the user on our own end, doesn't send user to authenticate to gmail.
Just give it a try.
Here's the download link.
http://svetlozar.net/downloads/import.zip
refer this.
Google Authentication API Library with PHP for User Details
http://www.technew.in/forum_thread_621_Google-Authentication-API-Library-with-PHP-for-User-Details.html
You can find how to fetch emails on this link, the problem was on the example code.
This is part of the code refered in the link.
$req = new \apiHttpRequest("https://www.google.com/m8/feeds/contacts/default/full?max-results=9999");
$val = $client->getIo()->authenticatedRequest($req);
$xml = new \SimpleXMLElement($val->getResponseBody());
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');
foreach($result as $title)
{
$emails[] = $title->attributes()->address;
}