facebooksdk.net发布无法正常工作-无法将LoginButton.CurrentSession发布到 [英] facebooksdk.net publish not working - can't get LoginButton.CurrentSession to publish to

查看:54
本文介绍了facebooksdk.net发布无法正常工作-无法将LoginButton.CurrentSession发布到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个似乎很简单的问题-我正在尝试使用facebooksdk.net发布到用户供稿.

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.

首先,我使用以下命令进行安装,这将使我得到Facebook.Client版本0.9.91-alpha:

First, I install with the following command, which gets me Facebook.Client version 0.9.91-alpha:

Install-Package Facebook.Client -pre

接下来,我有一个LoginButton(并且我能够成功登录)

Next, I have a LoginButton (and I'm able to successfully login)

<fbc:LoginButton x:Name="_loginButton" 
SessionStateChanged="_loginButton_SessionStateChanged" Margin="0,15" />

现在,我想发布到提要中,因此我使用以下代码,直接从facebooksdk.net网站复制以进行发布:

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();
    }
}

我遇到的问题是_loginButton.CurrentSession无法解决.它已从此版本的Facebook.Client中删除了吗?如果是,现在正确的方法是什么?

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?

推荐答案

经过反复试验,我相信已经找到了答案.现在可以通过Session.ActiveSession.CurrentAccessTokenData.AccessToken访问AccessToken,这意味着代码行应为:

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);

这篇关于facebooksdk.net发布无法正常工作-无法将LoginButton.CurrentSession发布到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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