I've got what seems to be a pretty simple problem - I'm trying to use the facebooksdk.net to publish to a users feed.
First, I install with the following command, which gets me Facebook.Client version 0.9.91-alpha:
Install-Package Facebook.Client -pre
Next, I have a LoginButton (and I'm able to successfully login)
<fbc:LoginButton x:Name="_loginButton"
SessionStateChanged="_loginButton_SessionStateChanged" Margin="0,15" />
Now, I want to post to the feed, so I use the following code, copied directly from the facebooksdk.net site for publishing:
private async void PublishStory()
{
await _loginButton.RequestNewPermissions("publish_stream");
var facebookClient = new Facebook.FacebookClient(_loginButton.CurrentSession.AccessToken);
var postParams = new
{
name = this.PostTitle,
message = _txtStatus.Text.Trim(),
description = this.PostDescription.Replace(@"""", "'"),
link = this.PostUrl,
picture = this.PostImageUrl,
actions = new {
name = this.PostAppName,
link = this.PostAppUrl,
},
};
try
{
dynamic fbPostTaskResult = await facebookClient.PostTaskAsync("/me/feed", postParams);
var result = (IDictionary<string, object>)fbPostTaskResult;
var successMessageDialog = new Windows.UI.Popups.MessageDialog("Posted Open Graph Action, id: " + (string)result["id"]);
await successMessageDialog.ShowAsync();
}
catch (Exception ex)
{
ShowLoginUI();
}
}
The problem I'm running into is that _loginButton.CurrentSession cannot be resolved. Was it removed from this version of Facebook.Client, and if so, what's the right way to do this now?
After some trial and error, I believe I've found the answer. The AccessToken is now accessible via Session.ActiveSession.CurrentAccessTokenData.AccessToken, which means the line of code should be:
var token = Session.ActiveSession.CurrentAccessTokenData.AccessToken;
var fbClient = new Facebook.FacebookClient(token);
来源:https://stackoverflow.com/questions/28310848/facebooksdk-net-publish-not-working-cant-get-loginbutton-currentsession-to-pu