Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

We have 3 problems related Social Networking (FaceBook, Instagram, Twitter)

$
0
0

1) Problem With FaceBook :-

Not sure if this is a Component error, or a Facebook App setup issue, but basically getting an 'could not read the username from the me API call' error using Xamarin.Social for Facebook. Basic work flow is says no Facebook accounts, redirects to the login, authenticate, then gives me a 'Success' but same error as above
screenshot image below.
Kindly assist us on the same

My Face Book Code is below:-

btnfacebook.TouchUpInside += (sender, ea) => {
//PostToMyWall ();
//Share (Facebook, btnfacebook);
var root = new RootElement ("Xamarin.Social Sample");

            var section = new Section ("Services");

            var facebookButton = new StringElement ("Share with Facebook");
            facebookButton.Tapped += delegate 
            {
                try
                {
                    Share (Facebook, facebookButton); 
                }
                catch (Exception ex)
                {
                    ShowMessage("Facebook: " + ex.Message);
                }
            };

            section.Add (facebookButton);
            root.Add (section);

            dialog = new DialogViewController (root);

            window = new UIWindow (UIScreen.MainScreen.Bounds);
            window.RootViewController = new UINavigationController (dialog);
            window.MakeKeyAndVisible ();

            //return true;
        };

Xamarin.Social.ShareResult shareResult;
private void Share (Xamarin.Social.Service service, StringElement button)
{

        //Xamarin.Social.ImageData img = new Xamarin.Social.ImageData(ShareImage.Image);
        List<Xamarin.Social.ImageData> list = new List<Xamarin.Social.ImageData>();
        list.Add(ShareImage.Image);
        Xamarin.Social.Item item = new Xamarin.Social.Item {
            Text = ShareText.Text,
            Images = list,//Images = Sh,
            //Links = new List<Uri> {
                //new Uri ("http://xamarin.com"),
            //},
        };

        UIViewController vc = service.GetShareUI (item, shareResult => {
            dialog.DismissViewController (true, null);
            //Window.Hidden = true;
            Window.MakeKeyAndVisible();
            //button.GetActiveCell().TextLabel.Text = service.Title + " shared: " + shareResult;
        });
        dialog.PresentViewController (vc, true, null);

}

public static FacebookService Facebook
{
get
{
if (mFacebook == null)
{
mFacebook = new FacebookService() {
//ClientId = "1514477548835117",
//ClientId = "1422930544690399",
ClientId = "368506793353448",
RedirectUrl = new Uri ("http://www.facebook.com/connect/login_success.html")//,
//Scope = "publish_actions"
};
}
return mFacebook;
}
}

=====================================================================================================================

2) Problem Twitter Login :-

I have used Following Code For Twitter Login. But we want to generate a code where if a twitter account is already logged-in in our device then twitter login through our application should be direct without asking for login. We need this on order to fetch twitter data.
We need same assistance for Facebook and instagram as well.

// Twitter Info

    void LoginToTwitter(bool allowCancel)
    {
        //LoginBehavior = LoginBehavior.Native;
        var auth = new OAuth1Authenticator(
            //"DynVhdIjJDZSdQMb8KSLTA",
            //"REvU5dCUQI4MvjV6aWwUWVUqwObu3tvePIdQVBhNo",
            "se8hTrJBQ7LSQuiC0GeHfxg5I",
            "7ISuVrAVSjPr9191scf3DJBWSlIqH1AWqLGamRBhP3IRXapo4K",
            new Uri("https://api.twitter.com/oauth/request_token"),
            new Uri("https://api.twitter.com/oauth/authorize"),
            new Uri("https://api.twitter.com/oauth/access_token"),
            new Uri("http://twitter.com"));

        //save the account data in the authorization completed even handler
        auth.Completed += async (s, eventArgs) =>
        {
            // We presented the UI, so it's up to us to dismiss it.
            dialog.DismissViewController (true, null);

            // For token
            //if(e.IsAuthenticated){


            if (!eventArgs.IsAuthenticated) {

                return;
            }
            //if (eventArgs.IsAuthenticated)
            else
            {
                //btnPost.Enabled = true;
                //btnSearch.Enabled = true;
                //btnTimeLine.Enabled = true;
                loggedInAccount = eventArgs.Account;
                //save the account data for a later session, according to Twitter docs, this doesn't expire
                //AccountStore.Create().Save(loggedInAccount, "Twitter");
                GetTwitterData();
                //DismissViewController(true, null);

            }
        };

        var ui = auth.GetUI();
        dialog.PresentViewController(ui, true, null);
    }

    Xamarin.Auth.Account loggedInAccount;
    partial void btntwitter_TouchUpInside (UIButton sender)
    {
        facebook = new Section ("Twitter");
        dialog = new DialogViewController (new RootElement ("Food Moves Twitter Login") {
            facebook,
        });

        window = new UIWindow (UIScreen.MainScreen.Bounds);
        window.RootViewController = new UINavigationController (dialog);
        window.MakeKeyAndVisible ();
        LoginToTwitter (true);
    }

    async public void GetTwitterData()
    {
        //use the account object and make the desired API call
        var request = new OAuth1Request(
            "GET",
            new Uri("https://api.twitter.com/1.1/account/verify_credentials.json "),
            null,
            loggedInAccount);

        await request.GetResponseAsync().ContinueWith(t =>
            {
                var res = t.Result;
                var resString = res.GetResponseText();
                Console.WriteLine("Result Text: " + resString);
                var jo = Newtonsoft.Json.Linq.JObject.Parse(resString);
                var imageUrl = (string)jo["profile_image_url"];
                imageUrl = imageUrl.Replace("_normal.",".");
                UIImage img = new UIImage();
                var nsu = new NSUrl(imageUrl);
                var nsd = NSData.FromUrl(nsu);
                img = UIImage.LoadFromData(nsd);
                InvokeOnMainThread(delegate
                    {
                        Cameraimage = img;


                    });
            });
    }

=====================================================================================================================

3) Instagram Login:

I am unable to code for sharing feature for instagram as i need a sharing feature from my application to instagram.
In short we need data to get posted from our application to instagram application.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>