开发者

LiveID API fails - missing token

I'm trying to retrieve some information from the LiveID API but am getting the error:

The provided request does not include an access token. An access token is
required in order to request this resource.

the code is relatively simple; I'm including the library, calling the initialiser with the nameidentifier claim I get from WIF and then requesting the me path.

from the error message I surmise I failed to provide an access token... but wouldn't my app have this already 开发者_如何学Csince I successfully retrieved the claim?

here's my code:

<script src="https://js.live.net/v5.0/wl.js" type="text/javascript"></script>

<script type="text/javascript">
WL.init({ client_id: 'O0UpnnhoiFljBJAtTxhVliu4qtbUWoEVxdgfK7SBR+M=' });
WL.api({ path: "me", method: "GET" }, function (response) {
    // response.error.message
});

* update *

it occurred to me perhaps I need to log into the system so I now have:

WL.init({ client_id: 'O0UpnnhoiFljBJAtTxhVliu4qtbUWoEVxdgfK7SBR+M=' });
WL.login();
WL.api({ path: "me", method: "GET" }, function (response) {

but same error...


so it was a little more complicated... apparently one has to create an application with the LiveID system at:

https://manage.dev.live.com/

the site give you a ClientID and then the code needs to be like this:

<script src="https://js.live.net/v5.0/wl.js" type="text/javascript"></script>
<script type="text/javascript">
WL.init({ client_id: '#YOUR-CLIENT-ID-HERE#' });
WL.login({ scope: ["wl.signin"] });
WL.api({ path: "me", method: "GET" }, function (response) {
    alert(response.first_name + ' ' + response.last_name);
});

interestingly, the ekkis I see myself logged in as everywhere doesn't appear anywhere and I'm confused now but I think I've been using a Passport account, thinking it was a LiveID account. I'm not sure I understand what the difference is but now that I've configured my LiveID account to have a first/last name it all works.

one final note: creating the app on the live.com site requires one to provide a return url. when the WL.login() gets called, the browser pops up a window requesting the user for permissions (even though s/he has already signed on). When the user clicks Ok, the return url is loaded INTO THAT WINDOW. grr... so now you have to have a special page that all it does is close the window (unless someone else here can suggest how it's supposed to work).

* update *

what I had wanted was the bloody e-mail (I can get it from all the other IPs). so to do that:

WL.login({ scope: ["wl.signin", "wl.emails"] });

and then:

WL.api({ path: "me", method: "GET" }, function (response) {
    $('#Auth .SignedIn').html(response.emails.account);
});

that will get the e-mail address associated with the account. there are other e-mails available, see: http://msdn.microsoft.com/en-us/library/hh243648.aspx#user

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜