Locked REST Calls with PHP

  • Monday, August 09, 2010 9:38 PM
     
      Has Code

    I want to access user profile and contacts. I am using OAuth WRAP and I can get Access Token but further I dont know "how to send HTTP get request using PHP for getting contacts" or profile or both ?

    I have read this document http://msdn.microsoft.com/en-us/library/ff751708.aspx

    but i m confused how can i include all of the following in HTTP headers: 

    GET / HTTP/1.1
    Host: apis.live.net
    Accept: application/json
    Content-Type: application/json
    Authorization: WRAP access_token=AuthToken 
    as in php there are two methods for sending http header 
    file_get_contents, curl but both takes url only. 
    Any guide, help or suggestion will be appreicated.

All Replies

  • Monday, October 18, 2010 1:56 PM
     
      Has Code

    Hi there...

    you have to setup the authorization in curl_options HTTPHEADER.

    Short request sample using curl:

     // Service endpoint for HTTP GET request
     $url_string = 'http://apis.live.net/V4.1/cid-CID/Contacts/AllContacts';
     $curl_session = curl_init($url_string);
     
     // build HTTP header with authorization code
     $curl_options = array(
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_HTTPHEADER => array(
       'Authorization: WRAP access_token=AuthToken="'.$_SESSION['wl_AuthToken'].'"',
       'Accept: application/json'
      )
     );
    
     // setup options for curl transfer
     curl_setopt_array($curl_session, $curl_options);
    
     // execute session and get response
     $curl_response = curl_exec($curl_session);
    
     // show response code
     print $curl_response;
    
     // close session
     curl_close($curl_session);
    

    hope it may be helpful. :-)

    kind regards,
    McGenesis