2012-05-22 83 views
0

我想获得当前Facebook用户的Silverlight游戏,不是在.NET页面中托管,只是一个HTML页面。 silverlight游戏将使用他们的id作为提交高分的凭证。获取当前的Facebook用户ID

我不希望他们使用我的应用程序登录Facebook。我希望他们在我的应用程序之外登录Facebook。然后我的应用程序使用Graph API的.Get(“我”)进行检查。但是,.Get(“我”)总是返回null。即使facebookClient具有应用程序访问令牌或appid +秘密。

我正在使用C#facebook sdk版本5.4.1.0(用于SL4支持)。

这是我尝试做使用的appid +秘密:

 var app = new Facebook.FacebookClient(appId, appSecret); 
     app.GetCompleted += new EventHandler<Facebook.FacebookApiEventArgs>(app_GetCompleted); 
     app.GetAsync("me"); 
    } 

    void app_GetCompleted(object sender, Facebook.FacebookApiEventArgs e) 
    { 
     //the value of me below is always null 
     var me = e.GetResultData() as IDictionary<string, object>; 
     string id = (string)me["id"]; 
    } 

根据其他网站的应用程序访问令牌应该是绰绰有余,以获得当前的Facebook用户的ID:

我在做什么错误/误解获取当前的Facebook用户ID?

编辑:调试信息

Fiddler2结果404:

"message": "(#803) Some of the aliases you requested do not exist: clientaccesspolicy.xml", 
    "type": "OAuthException", 
    "code": 803 

Fiddler2导致400:

"message": "An active access token must be used to query information about the current user.", 
    "type": "OAuthException", 
    "code": 2500 

FacebookApiEventArgs e.Error.Message:

Value cannot be null. Parameter name: stream 

FacebookApiEventArgs e.Error.StackTrace:

at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen) 
    at System.IO.StreamReader..ctor(Stream stream) 
    at Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper, Stream responseStream, Type resultType, String& responseStr, Exception& exception, Boolean& cancelled) 

回答

1

使用Facebook C#SDK:

string signedRequest = Request.Form["signed_request"]; 
var DecodedSignedRequest = FacebookSignedRequest.Parse(Facebook.Web.FacebookWebContext.Current.Settings.AppSecret, signedRequest); 
dynamic SignedRequestData = DecodedSignedRequest.Data; 
accessToken = (String)SignedRequestData.oauth_token; 
var app = new FacebookWebClient(); 
var me = (IDictionary<string, object>)app.Get("me"); 
firstName = (string)me["name"]; 
U_Id = (string)me["id"]; 
+1

谢谢。看起来需要身份验证才能获取在.Get(“我”) – ShawnFeatherly

+0

Your Welcome :)中找到的任何公共数据:) –

1

尝试运行的Fiddler在执行上面提到的代码。然后你可以期待Facebook的回应。例如,Facebook OAuthExceptions。

http://www.fiddler2.com/fiddler2/version.asp

+0

感谢肖恩,我更新了来自fiddler2和VS2010调试信息的帖子。我不明白为什么有OAuthExceptions。我只想要公开信息。它不应该做任何认证,对吧? – ShawnFeatherly