1

I'm posting on Facebook by using Xamarin.Social component. It's not giving any error but not posting anything. I'm login in to the Facebook as mentioned below.

This is written in CustomRenderer for Login Page

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

On successful login, system takes user to a landing screen. From their user clicks on a button which will post certain information(link) on Facebook.

This is the code which I used to post info on 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);
    }
});

Please let me know what is the issue with the existing code.

Thanks.

jzeferino
  • 7,700
  • 1
  • 39
  • 59
Brijesh
  • 369
  • 2
  • 10

0 Answers0