Tim Windsor
Tim Windsor

Reputation: 329

C#-Facebook-SDK WP7, the principles of how Facebook works?

Apologies if this is somewhere, but I'm struggling to find the details I need for wp7.

I have created the application on Facebook as required, and am retrieving an access token. The following code posts to Facebook but I cannot get a response, nor can I work out how to monitor the response?

public bool fbUpload(string accessToken, Picture pic)
    {
        try
        {
            Stream s = null;
            s = PicturesLoader.LoadFileFromStorage(pic.Url);

            //Sets the byte array to the correct number of bytes
            byte[] imageData = new byte[s.Length];

            s.Read(imageData, 0, System.Convert.ToInt32(s.Length));

            FacebookApp app = new FacebookApp();
            IDictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("access_token", accessToken);
            parameters.Add("message", "TEST - WP7 application [upload pic and comment on wall...]");
            var mediaObject = new FacebookMediaObject { FileName = pic.Name, ContentType = "image/jpeg" };
            mediaObject.SetValue(imageData);

            parameters["source"] = mediaObject;
            FacebookAsyncResult postResult;
            FacebookAsyncCallback fbCB = new FacebookAsyncCallback();
            app.PostAsync(parameters, fbCB);



    return true;
        }
        catch (InvalidCastException ex)
        {
            return false;
        }
    }

The other question I have, is how do you allow users to allow access based upon their own Facebook account. I want to store a user's account details so they only have to set up the account details once, and then they can use my phone app with having to sign in?

Upvotes: 1

Views: 569

Answers (1)

Magnus Johansson
Magnus Johansson

Reputation: 28325

You can handle the post result something like this:

FacebookAsyncCallback callBack = new FacebookAsyncCallback(postResult);
fbApp.PostAsync(parameters, args, callBack);  

private void postResult(FacebookAsyncResult asyncResult)   
{
  // Do something with asyncResult here;
}

Regarding the second question, you must ask for permissions to access this data. You usually do that in the FacebookOAuthClient.GetLoginUrl(<appId>, null, <permissions>) method call.
Once that's done, you can store the files you have permissions to locally in your app.

Upvotes: 2

Related Questions