2

Hello i'm using unofficial x-box one api for sending messages over x-box live accounts.Here is my code sample and error(Problem).

Code:

<?php
     $arr = array('to' => array("gamoneybcn"), 'message' => "This is an Test Test example message sent via XboxAPI.");

     $post = json_encode($arr);

     $proServiceUrl = "https://xboxapi.com/v2/messages/";
     $contentsType = 'application/json';          
     $methods = 'POST';                   
     $auths = 'X-AUTH: XXXX';

     $profilesCurl = curl_init();
     curl_setopt($profilesCurl, CURLOPT_URL, $proServiceUrl);
     curl_setopt($profilesCurl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($profilesCurl, CURLOPT_POSTFIELDS, $post);
     curl_setopt($profilesCurl, CURLINFO_HEADER_OUT, true);
     curl_setopt($profilesCurl, CURLOPT_HTTPHEADER, Array('Content-type:'.$contentsType.';auth='.$auths));
     curl_setopt($profilesCurl, CURLOPT_HTTPHEADER, Array($auths));
     $profilesJson = curl_exec($profilesCurl);
     echo "<pre>";
     print_r($profilesJson);
     exit;
 ?>

Problem:

If i'm not logged in my x-box one unofficial developer account my api's not working and getting error code like below.

Error:

{"success":false,"error_code":401,"error_message":"A fresh login is required to gain a new token from Microsoft"}.

Note:

As soon as i logged in my x-box one api developer account the api will run.i have also try to first make curl authentication but i dont know is it possible after curl authentication? if is it possible by making first curl authentication so please helping me to solve out this problem as soon as possible.a big thanks in advance.

1 Answers1

1

I just ran into the same problem and this was my first search result.

When you initially link your Xbox API account with a Microsoft account, the Xbox API only stores the account email and an oAuth token, rather than saving your password. This token is only valid for a finite period of time, so you need to login to your Microsoft account through the Xbox API website periodically to generate new oAuth tokens for it.

In order to do this, go to your profile page on the Xbox API site and click the "Sign in to Xbox LIVE" on the bottom left.

Enter your account credentials and press "Sign in to Xbox LIVE", or click "Sign in to Xbox LIVE using oAuth" and it will direct you to login on the Xbox site. Both methods should essentially do the same thing since the site says it never stores or logs your password, but if you're paranoid go with the oAuth option.

ailurus
  • 33
  • 1
  • 8