Azure的移动服务与Facebook验证:获取用户信息 [英] Azure Mobile Service with Facebook Auth: Get user info

查看:120
本文介绍了Azure的移动服务与Facebook验证:获取用户信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来使用的Azure移动服务(或任何移动开发)。 我已经按照这个教程,使Facebook的身份验证的Andr​​oid应用程序。 <一href="http://azure.microsoft.com/en-us/documentation/articles/mobile-services-how-to-register-facebook-authentication/" rel="nofollow">http://azure.microsoft.com/en-us/documentation/articles/mobile-services-how-to-register-facebook-authentication/

I am new to using Azure Mobile Services (or any mobile dev). I've followed this tutorial to enable Facebook authentication for an Android app. http://azure.microsoft.com/en-us/documentation/articles/mobile-services-how-to-register-facebook-authentication/

我的移动业务有一个.NET后端和客户端的是Android。 我也设法访问令牌保存到一个表;

My Mobile Service has a .NET backend and client is Android. I've also managed to save the access token to a table;

public async Task<IHttpActionResult> PostTodoItem(TodoItem item)
    {
        var currentUser = User as ServiceUser;
        item.UserId = currentUser.Id;
        TodoItem current = await InsertAsync(item);
        return CreatedAtRoute("Tables", new { id = current.Id }, current);  
    }

保存的值是格式如下:Facebook的:907xxxxxxxxx757

The value saved is in this format: Facebook:907xxxxxxxxx757

我试图让使用Facebook SDK用户的名字。

I am trying to get the user's FirstName using the Facebook SDK.

var currentUser = User as ServiceUser;
        var accessToken = "current.Id";
        var client = new FacebookClient(accessToken);
        dynamic me = client.Get("me", new { fields = "name,id" });
        string firstName = me.name;

不过收到我的Andr​​oid虚拟设备(AVD)以下错误:{消息:一个错误发生} Eclipse的logcat的似乎不返回任何错误......我猜,因为它不是Android应用程序产生的错误,而是移动服务。

But receive the following error on my Android Virtual Device (AVD): "{message: an error has occured}" The Eclipse logcat doesn't appear to return any errors...I guess since it is not the Android App producing the error but rather the Mobile Service.

使用人的Facebook的名字(我当然不会有)的作品;

Using the person's Facebook name (which I off course will not have) works;

var currentUser = User as ServiceUser;
        var client = new FacebookClient();
        dynamic me = client.Get("zuck" });

为什么没有这种方法的工作?

Why doesn't this approach work?

或者是我的Facebook的令牌不正确的认识? 难道令牌或许生活在AVD,并为此移动服务不能使用该令牌?

Or is my understanding of the Facebook token incorrect? Does the token perhaps live on the AVD and therefor the Mobile Services can't use the token?

推荐答案

好像我的怀疑令牌是正确的。 这似乎工作..

Seems like my suspicion about the token was correct. This seems to work..

           var serviceUser = this.User as ServiceUser;
           var identities = await serviceUser.GetIdentitiesAsync();
           var fb = identities.OfType<FacebookCredentials>().FirstOrDefault();

           var client = new FacebookClient(fb.AccessToken);
           dynamic me = client.Get("me", new { fields = "name,id" });
           string firstName = me.name;
           string lastName = me.last_name;

这篇关于Azure的移动服务与Facebook验证:获取用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆