hotmail: user authentication and contact retrieval with PHP - php

I am trying to write a PHP script that will allow me to do two things:
Allow users to use their Hotmail (I think its called 'Live' now?) account to authenticate themselves to a website
Retrieve an authenticated users contact list from Hotmail.
I have trawled the internet for the past 6 hours, looking for at least a working example that I can modify/extend to do the above two things. There are several dozens similar questions asked here on SO for example - NONE of the proffered answers work any more (admittedly, some of the questions were a few years old).
I tried the Microsoft site and downloaded the latest version of their API which seems to evolve at a rather alarming rate. I finally managed to track down an API which has not been deprecated (yet?).
I followed the instructions and when I attempted to authenticate, I was rewarded with the following mesage, for my efforts:
We're unable to complete your request
Windows Live ID is experiencing technical difficulties. Please try again later.
I immediately tried the online version of the demo and perhaps unsurprisingly, that worked like a charm.
As an aside, I managed to implement the same functionality for Yahoo and GMail, using their OPEN APIs, under an hour each. Now, it is possible that my unmitigated hatred of all things proprietary (sorry make that Microsoft), is causing me to lose the plot a little here.
Has anyone ACTUALLY (in 2012) managed to get a working sample in PHP that allows:
Hotmail (live?) user authentication
Hotmail user contact email retrieval
If you have, a code snippet, or a link to where I can find such a snippet would be very useful, as I have so far, wasted a whole afternoon trying to work the Microsoft Live API via PHP.
PS: No, I'm not interested in OpenInviter, its broken.

i wrote my own oauth library based around a single array for each service provider. this array contains all of the data required to perform authentication and retrieve user data. the array i use for msdn (ie. hotmail, outlook, xbox, msn) is:
$msdn = array
(
'oauth_version' => '2',
'oauth_method' => 'GET',
'redirect_user_params' => array
(
'url' => 'https://oauth.live.com/authorize',
'response_type' => 'code',
'http_params' => array
(
'url',
'client_id',
'redirect_uri',
'response_type',
'scope',
'state'
)
),
'obtain_access_token_params' => array
(
'url' => 'https://oauth.live.com/token',
'grant_type' => 'authorization_code',
'http_params' => array
(
'url',
'client_id',
'client_secret',
'code',
'grant_type',
'redirect_uri',
'scope'
)
),
'scope' => 'wl.signin wl.basic',
'obtain_user_data_params' => array
(
'url' => 'https://apis.live.net/v5.0/me',
'http_params' => array
(
'url',
'access_token',
'scope'
)
),
'client_id' => 'xxxxx', // = oauth_consumer_key in oauth 1.0 lingo
'client_secret' => 'xxxxxxxxxxxxxxx',
'readme_url' => 'http://msdn.microsoft.com/en-us/library/live/hh243647.aspx'
);
the parameters for each of the three oauth stages (ie "redirect user", "obtain access token" and "obtain user data") are in the http_params arrays. in the case of msdn these parameters end up in the query query string of the url that i send out with curl (since msdn only accepts GET, not POST).
i haven't tried retrieving the user's contact address book, but this would just be a case of extending the scope element with whatever extra information you require (documented here http://msdn.microsoft.com/en-us/library/live/hh243646.aspx). as you can see from the http_params arrays, the scope parameter is used in each of the three oauth stages.

Try out a Hotmail/MSN/Live import on the CloudSponge test drive to see if that's the user experience you're hoping for.
If it works for you, you can use our widget or our API. If you want to use the API, we have a PHP wrapper already written for your convenience.

Please confirm your callback url is with http:// if you only put www.domain.com then get this issue..

Related

go through browser auth with rest requests - Gmail API

I would like to send email messages with our corporate emails provided by Gmail. In order to do that, I would like to use Gmail API with rest commands (basically launched with a php procedural code, for legacy purpose).
I have that code :
I go to this url :
// https://accounts.google.com/o/oauth2/auth?client_id=my_client_id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/gmail.send&response_type=code
// and obtain a token like that : 4/1AX4XfWgmW0ZdxXpJn8YzkVeDs3oXZUHyJcR7abE2TuqQrcmo4c1W02ALD4I
/*
echo GoogleAuthCurl("GET", '', array(
'client_id' => $GOOGLE_CLIENT_ID,
'redirect_uri'=>'urn:ietf:wg:oauth:2.0:oob',
'scope' => 'https://www.googleapis.com/auth/gmail.send',
'response_type' => 'code'
), array());
then I can use requests in curl for getting my access token :
curl \
--request POST \
--data "code=[Authentcation code from authorization link]&client_id=[Application Client Id]&client_secret=[Application Client Secret]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" \
https://accounts.google.com/o/oauth2/token */
$tokenJson = json_decode( GoogleTokenCurl("POST", '', array(), array(
'code' => '4/1AX4XfWiEWngRngF7qryjtkcOG1otVtisYpjHnej1E54Pujcrchef8REvdt0',
'client_id' => $GOOGLE_CLIENT_ID,
'client_secret' => $GOOGLE_CLIENT_SECRET,
'redirect_uri'=>'urn:ietf:wg:oauth:2.0:oob',
'grant_type' => 'authorization_code'
)
));
print_r($tokenJson);
This far, I've got food for my authorization header. My issue is in the first step (with the consent asked to user). I wish i can do this step without putting my url in the browser, validate two screens to grant access before getting the authorization code.
I'm also interested in advices to create gmail messages with rest requests driven by curl. I found postman collection about all actions gmail api can do, but one or two call examples wouldn't do harm ;)
thanks !
In the current state, by the method you are using, &response_type=code, you need two calls to the OAuth client to get the access token. You can find an example of how to handle it just using HTTP/REST requests here.
In any case, you could use Google API Client Library for PHP. Allows you to handle the OAuth authentication flow, only needing one interaction to get the token.
You can find a full example on how this works here, notice that this example uses the Drive API, if you want to use it within the Gmail API, you can check Gmail API PHP library.
Documentation:
PHP Gmail API
OAuth 2.0 to Access Google APIs

Hide URL in final tweet and leave only the card

I've developed an app in Laravel, using codebird-php, that's able to post tweets with images, videos and links. The code works as it's intended but I was told by my boss to hide the url in the final tweet and leave only the card, this for aesthetic purposes.
You can see what I'd like to do in the next pictures.
On top you can see a tweet from TechCrunch with a card but no url in body, this is wat I want to achieve.
However, I've also noted that there are tweets with cards and a visible url in the body. TechCrunch also as an example.
I've read into Twitter's API thinking the url might be an additional parameter as Facebook does, but I found nothing. I've also thought that it might be Twitter's site hiding the urls in web as in Twitter for Mac I can see the url.
I really don't know, I've been looking for a couple of days now and don't know what or how to do it. Does anyone know how to achieve that? Or am I right thinking that it's Twitter hiding the url in web?
Thank you all for your time.
EDIT:
Here's my code.
$sm = SocialScheduling::find($id);
$sm->update([
'persona_id' => $request->get('persona_id'),
'social_auth_id' => $request->get('social_auth_id'),
'social_scheduling_category_id' => $request->get('social_scheduling_category_id'),
'message' => $request->get('message'),
'post_link' => $request->get('post_link'),
'post_to_feed' => $request->get('ptf'),
'social_networks' => json_encode($request->get('social_networks')),
'facebook_pages' => json_encode($request->get('facebook_pages')),
'programmable_type' => $request->get('programmable_type'),
'programmable_id' => $request->get('programmable_id'),
'client_id' => $request->get('client_id'),
'image_url' => $request->get('image_url'),
'publish_time' => $request->get('publish_time')
]);
$sm->save();
$sm->load('persona','client','category','programmable','social_auth');
$persona = SocialAuth::find($sm->social_auth_id);
Codebird::setConsumerKey( Config::get('services.twitter.client_id'),
Config::get('services.twitter.client_secret'));
$tw = Codebird::getInstance();
$tw->setToken($persona->twitter_token,$persona->twitter_token_secret);
$data = [
'status' => $sm->message
];
$reply = $tw->statuses_update($data);
What my code does is it updates the SocialScheduling model, then it uses social_auth_id to find the model with the credentials and assigns it to $persona, afterwards I build the tweet adding the url to the tweet message, but I'd like to know if there's an additional parameter, like Facebook does, where I can send the url. I didn't see anything in Twitter's docs.

Replying to a private message as a Facebook page

I created a tool for our support team that gets all private messages from our +/- 70 Facebook fan pages for easy processing and not having to manually click through all the pages to check if there are new or unanswered messages.
This tool worked perfectly for a couple of months but recently we've been getting the following error when trying to send a reply on a private message:
[error] => Array
(
[message] => (#504) Invalid reply thread id
[type] => OAuthException
[code] => 504
)
My code is as follows:
$fb->setAccessToken('%access_token%');
$edge = 't_id.' . $thread['id'] . '/messages';
$result = $fb->api($edge, 'POST', array('message' => $message));
I use extended access tokens but just to be sure I renewed them all. The value in $thread['id'] is the value from 'thread_id' from querying FQL 'message' table.
I searched in the Facebook docs but it looks like they removed everything concerning this subject, which could imply they removed the functionality entirely.
They say something about a new messages system which they are rolling out on the thread reference page, but I can't find anything else about this subject. https://developers.facebook.com/docs/reference/api/thread/
EDIT:
As you can see in the comments the documentation can be found here: https://developers.facebook.com/docs/graph-api/reference/page/conversations
I just made a new page for testing and I can't seem to get a valid access token in the graph api exlorer for accessing the edge /{page-id}/conversations. I remember this has happened before when I was developing my tool. The same access tokens didn't work for a week and then suddenly started working again...

Google API - allow connections only with Google Apps Domain

Is it possible to allow a client to connect to the API ONLY with a google apps domain email address? Users often have their own gmail session active and we need to ensure that they can only connect to the api using our Google Apps Domain email.
For now the only solution has been that we disconnect them when they return from the auth steps if their email address doesnt contain our domain, with an error message telling them they need to follow the steps again using their [domain].com email address, which is far less than ideal. Can the domain be specified somewhere in the scopes or api console for example?
[Google API PHP Client]
I found a hacky solution, describing briefly for those who may need smth similiar:
If you add the login_hint parameter with the email address (in this case with Google Apps account, with our own domain) it bypasses the initial login page and if any other google sessions are available bypasses them as well. I didn't find this behavior described in the documentation, nor did I find the ability to add this parameter in the google-api-php-client. I added a method in the Google_Client.php file to allow the ability to add the login_hint parameter:
public function setLoginHint($loginHint) {
global $apiConfig;
$apiConfig['login_hint'] = $loginHint;
self::$auth->login_hint = $loginHint;
}
And the parameter to the authenticate method in Google_Oauth2.php:
$request = Google_Client::$io->makeRequest(new Google_HttpRequest(self::OAUTH2_TOKEN_URI, 'POST', array(), array(
'code' => $code,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->redirectUri,
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'login_hint' => $this->loginHint
)));
Then I can call the method using the user's Google Apps email address during authentication:
$client->setLoginHint("user#mydomain.com")
If there was something built in that I didnt find in the docs or searches please let me know. By the way, I thought Google API guys were keeping an eye on SO for questions such as these, echo echo...

Evernote Integration With PHP

I have successfully done with the authentication of Evernote with PHP.
And I have got this response.
Array ( [oauth_token] => S=s1:U=6316e:E=144fcfdfdb9:C=13da54cd1ba:P=185:A=maheshchari-2599:V=2:H=6da806fe92b9289cf0334f04e2afdc55 [oauth_token_secret] => [edam_shard] => s1 [edam_userId] => 405870 [edam_expires] => 1395813907897 [edam_noteStoreUrl] => https://sandbox.evernote.com/shard/s1/notestore [edam_webApiUrlPrefix] => https://sandbox.evernote.com/shard/s1/ )
Now, I want the list of notebooks of the user which has been authenticated with evernote.
I have done a lot of research online but I couldnt find any thing which helps, I have came to know that guid is necessary to get the list of notebooks.
From where I can find that? And how can i access the notestore and userstore?
How can i call the functions of notestore and userstore to fetch the data of user's account and user's notes in php?
Thanks in Advance.
Using the Evernote SDK for PHP, you can list notebooks like the way below:
$client = new Client(array('token' => $authToken));
$noteStore = $client->getNoteStore();
$notebooks = $noteStore->listNotebooks();
All the API references can be found here.
Also, you shouldn't make your token public. Please make sure your token string you put can't be used any more. If you need more help on this, you can get supports from Evernote developer support.
https://github.com/evernote/evernote-sdk-php
go to this link and download this zip then go to sample folder then go to client folder and run EDAMTest.php page.
and add authtoken.

Categories