Add contact for Impersonation Account - php

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

Related

Access shared mailbox through o365 v2 api

So I got access to the new o365 v2 api and it's working pretty good so far. I am however having trouble accessing any shared inboxes.
Even worse, there doesn't appear to be any error message being returned:
#odata.context = https://outlook.office.com/api/v2.0/$metadata#Me/Messages(Subject,ReceivedDateTime,SentDateTime,Sender,From,ToRecipients,CcRecipients,BccRecipients,ReplyTo,ConversationId,IsRead,InternetMessageId
[value] =
Has anyone ever tried this?
To clarify, this isn't for exchange, but outlook.com
It seems that you were using the delegate-token to request the message from the specific user for the messages in a shared box.
The Office 365 REST API only support app-level token to get the messages from the organization. The delegate-token only could get the messages of the delegatee user.
You can also consider using the EWS to retrieve the messages of shared box as a workaround.
Here is an example for your reference:
string userName = "";
string password = "";
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new NetworkCredential(userName, password);
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl(userName, RedirectionUrlValidationCallback);
FolderId SharedMailbox = new FolderId(WellKnownFolderName.Inbox, "sharedmailbox#consoto.onmicrosoft.com");
ItemView itemView = new ItemView(10);
var results = service.FindItems(SharedMailbox, itemView);
foreach (var item in results)
{
Console.WriteLine(item.Subject);
}
And if you want the Office 365 REST API to support this feature, you can also submit the feedback from here.

How to update Google Sheets file with API PHP Client

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.

Google contacts via API

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);

ZendFramework Google Contacts

I am using the following
http://www.ibm.com/developerworks/opensource/library/x-phpgooglecontact/index.html
to authenticate to Google and retrieve a users contacts. However I would prefer this system to use Google's oAuth integration.
What is the easiest way to do this or a simple example?
Essentially I want to modify this
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'cp');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
// perform query and get feed of all results
$query = new Zend_Gdata_Query(
'http://www.google.com/m8/feeds/contacts/default/full');
$query->maxResults = 1000;
$query->setParam('sortorder', 'descending');
$feed = $gdata->getFeed($query);
Such that it now uses oauth2 such that a user never has to give their email or password.
I found the following tutorial which resolved my problem.
http://leandroardissone.com/post/1330339821/google-contacts-php

Exchange Server 2007 Web Services PHP Class

Does anyone know of an open source PHP class (preferably BSD or MIT license) that will interface with the MS Exchange Server 2007 Web Services via. SOAP?
I am looking for a higher level class that has functionality for sending messages via. the web service.
I had this same problem, so I started building something, here:
https://github.com/rileydutton/Exchange-Web-Services-for-PHP
It doesn't do much yet (basically just lets you get a list of email messages from the server, and send email), but it would be good enough to use as a basic starting point for doing some more complicated things.
I have abstracted out a good bit of the complexity that you would have to slog through using php-ews. If you are looking to do some raw, powerful commands with the server, I would use php-ews...this is for folks who just happen to be working with an Exchange server and want an easy way to do some basic tasks.
Oh, and it is MIT licensed.
Hope that someone finds it useful!
Here is a class that you need: php-ews (This library makes Microsoft Exchange 2007 Web Services easier to implement in PHP).
You could find it at: http://code.google.com/p/php-ews/
There is only one example but that should give you the way to implement it.
Below you can find an implementation in order to:
connect to server
get the calendar events
Note: don't forget to fill-in blank variables. You would also need to include php-ews classes files (I used the __autoload PHP function).
$host = '';
$username = '';
$password = '';
$mail = '';
$startDateEvent = ''; //ie: 2010-09-14T09:00:00
$endDateEvent = ''; //ie: 2010-09-20T17:00:00
$ews = new ExchangeWebServices($host, $username, $password);
$request = new EWSType_FindItemType();
$request->Traversal = EWSType_FolderQueryTraversalType::SHALLOW;
$request->CalendarView->StartDate = $startDateEvent;
$request->CalendarView->EndDate = $endDateEvent;
$request->CalendarView->MaxEntriesReturned = 100;
$request->CalendarView->MaxEntriesReturnedSpecified = true;
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = $mail;
$response = $ews->FindItem($request);
echo '<pre>'.print_r($response, true).'</pre>';
Exchange server supports WebDAV:
http://www.troywolf.com/articles/php/exchange_webdav_examples.php
If all you want to do is send messages, you could just use SMTP:
http://ca2.php.net/manual/en/book.mail.php
I have been researching this same issue and I have yet to find a class specific to MS Exchange. However, if you feel up to learning and building the XML yourself, you may want to have a look at the NTLM SOAP classes at http://rabaix.net/en/articles/2008/03/13/using-soap-php-with-ntlm-authentication. This will allow you to authenticate against Active Directory to make your SOAP calls, which native PHP SOAP does not allow you to do. Another decent resource that uses the same method to connect to MS CRM is http://www.reutone.com/heb/articles_internet.php?instance_id=62&actions=show&id=521.
The examples under http://www.troywolf.com/articles/php/exchange_webdav_examples.php are for Exchange 2003 not 2007.

Categories