1

我使用 Xamarin.Social 组件在 Facebook 上发帖。它没有给出任何错误,但没有发布任何内容。我正在登录 Facebook,如下所述。

这是CustomRenderer为登录页面编写的

protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
    base.OnElementChanged(e);

    var activity = this.Context as Activity;

    var auth = new OAuth2Authenticator (
        clientId: "XXXXXXXXXXXXX", 
        scope: "email + public_profile + publish_actions", 
        authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"), 
        redirectUrl: new Uri ("http://www.XXXXXXX.sv/"));   

    auth.Completed += (sender, eventArgs) =>
    {
        if (eventArgs.IsAuthenticated)
        {
            //UserInfo is a static class which will hold the account object.
            UserInfo.oFaceBookAccount = eventArgs.Account;
            App.SuccessfulLoginAction.Invoke();

            string _token = eventArgs.Account.Properties["access_token"];
            App.SaveToken(_token);
        }
        else
        {
            // The user cancelled
        }
    };
    activity.StartActivity(auth.GetUI(activity));
}

成功登录后,系统会将用户带到登录屏幕。从他们的用户点击一个按钮,该按钮将在 Facebook 上发布某些信息(链接)。

这是我用来在 Facebook 上发布信息的代码:

MagingCenter.Subscribe<ProfilePage, Messanger> (this, "onFaceBookShare", async (sender, args) => 
{
    try 
    {
        var Facebook = new FacebookService ();
        Facebook.ClientId = "XXXXXXXX"; //it is same as i used while login
        Facebook.RedirectUrl = new Uri ("http://www.XXXXXX.com/");

        var item = new Xamarin.Social.Item (){ Text = "Test Msg." };

        item.Links.Add (new Uri ("http://www.t.sv/"));
        var account = UserInfo.oFaceBookAccount;
        Facebook.ShareItemAsync (item, account);

    } catch (Exception ex) 
    {
        Console.WriteLine (ex.Message);
    }
});

请让我知道现有代码有什么问题。

谢谢。

4

0 回答 0