0

I'm trying to get the current facebook user for a silverlight game that is not hosted in a .NET page, just an html page. The silverlight game will use their id as a credential for submitting a highscore.

I don't want them to login to Facebook using my app. I want them to login to facebook outside of my app. Then my app checks using .Get("me") of the Graph API. However, .Get("me") always returns null. Even if the facebookClient has an App access token or appid+secret.

I'm using the C# facebook sdk version 5.4.1.0 (for SL4 support).

This is how I try to do it using appid+secret:

        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"];
    }

According to other sites the Apps access token should be more than enough to get the id of the current facebook user:

What am I doing wrong/misunderstanding to get the current facebook users id?

Edit: debug info

Fiddler2 result 404:

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

Fiddler2 result 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)
Community
  • 1
  • 1
ShawnFeatherly
  • 2,470
  • 27
  • 20

2 Answers2

1

Try running Fiddler while executing the code mentioned above. You can then expect the response back from Facebook. For example, Facebook OAuthExceptions.

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

Shaun Danielz
  • 571
  • 1
  • 4
  • 5
  • Thanks Shaun, I updated the post with Debug info from both fiddler2 and VS2010. I don't understand why there are OAuthExceptions. I only want the public information. It shouldn't have to do any authentication, right? – ShawnFeatherly May 22 '12 at 08:04
1

Using 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"];
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Eslam Soliman
  • 1,276
  • 5
  • 16
  • 42