简体   繁体   English

使用新的Office365 API授权

[英]Authorization with new Office365 API

I have started an attempt at utilizing the new Office 365 API. 我已经开始尝试利用新的Office 365 API。 I am having some issues though. 我有一些问题。

I have successfully retrieved an access_token but the documentation doesn't tell me what to do with it. 我已经成功检索了一个access_token,但是文档没有告诉我该怎么做。

Has anyone else done this successfully, or alternatively can you have a quick read over the documentation and shed some light on it? 是否有其他人成功完成了此操作,或者您可以快速阅读文档并对此有所了解吗?

Thanks 谢谢

Edit: Forgot the link - http://msdn.microsoft.com/en-us/library/office/dn605896.aspx 编辑:忘记链接-http : //msdn.microsoft.com/zh-cn/library/office/dn605896.aspx

The documentation to use PHP and Office365 API according to my research is almost inexistent but... I was able to use Office API by using this PHP class to process the oauth connection: 根据我的研究,几乎没有使用PHP和Office365 API的文档,但是...通过使用此PHP类来处理oauth连接,我能够使用Office API:

http://www.phpclasses.org/package/7700-PHP-Authorize-and-access-APIs-using-OAuth.html http://www.phpclasses.org/package/7700-PHP-Authorize-and-access-APIs-using-OAuth.html

Hope it helps! 希望能帮助到你!

Using this class you will be able to access like this: 使用此类,您将可以像这样访问:

// Oauth to Office365
$office_oauth = new oauth_client_class;
$office_oauth->debug = true;
$office_oauth->debug_http = false;

$office_oauth->redirect_uri = 'http://' . $_SERVER['HTTP_HOST'];

$office_oauth->client_id = 'YOUR_CLIENT_ID';
$office_oauth->client_secret = 'YOUR_CLIENT_SECRET';

$office_oauth->dialog_url = 'https://login.windows.net/common/oauth2/authorize?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&state={STATE}&scope={SCOPE}&resource='.UrlEncode("https://outlook.office365.com/");
$office_oauth->access_token_url = 'https://login.windows.net/common/oauth2/token';

$office_oauth->oauth_version = 2;
$office_oauth->url_parameters = 1;
$office_oauth->authorization_header = 1;
$office_oauth->exit = 0;

$office_oauth->scope = 'YOUR_SCOPES';

if (($officeSuccess = $office_oauth->Initialize())) {

    $officeSuccess = $office_oauth->Process();
    $officeSuccess = $office_oauth->Finalize($officeSuccess);
}

if ($office_oauth->exit) {
    exit;
}

The access token should be embedded in the request when calls the resource (please find the 9th). 调用资源时 ,访问令牌应嵌入请求中 (请找到第9个)。 So I'm guessing you need to provide your access token in your request headers, for instance: 因此,我猜测您需要在请求标头中提供访问令牌,例如:

context.SendingRequest2 += (s, e) => { e.RequestMessage.SetHeader("Authorization", "Bearer " + accessToken); };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM