Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not Logged In Issue #8

Open
huxaiphaer opened this issue Oct 13, 2017 · 2 comments
Open

Not Logged In Issue #8

huxaiphaer opened this issue Oct 13, 2017 · 2 comments

Comments

@huxaiphaer
Copy link

huxaiphaer commented Oct 13, 2017

I implemented everything in your video but when i press the butto says the following:
"Not Logged In. you are not logged in. please login and try again"

Below is my code :

using System;
using System.Collections.Generic;
using diabetics_app.ViewModels;
using Xamarin.Forms;

namespace diabetics_app.Main
{
    public partial class FacebookProfilePage : ContentPage
    {
		/// <summary>
		/// Make sure to get a new ClientId from:
		/// https://developers.facebook.com/apps/
		/// </summary>
		private string ClientId = "134161603894277";
       // 134161603894277
		public FacebookProfilePage()
		{
			InitializeComponent();

			var apiRequest =
				"https://www.facebook.com/v2.10/dialog/oauth?client_id="
				+ ClientId
				+ "&display=popup&response_type=token&redirect_uri=http://www.facebook.com/connect/login_success.html";

			var webView = new WebView
			{
				Source = apiRequest,
				HeightRequest = 1
			};

			webView.Navigated += WebViewOnNavigated;

			Content = webView;
		}

		private async void WebViewOnNavigated(object sender, WebNavigatedEventArgs e)
		{

			var accessToken = ExtractAccessTokenFromUrl(e.Url);

			if (accessToken != "")
			{
				var vm = BindingContext as FacebookViewModel;

				await vm.SetFacebookUserProfileAsync(accessToken);

				Content = MainStackLayout;
			}
		}

		private string ExtractAccessTokenFromUrl(string url)
		{
			if (url.Contains("access_token") && url.Contains("&expires_in="))
			{
				var at = url.Replace("https://www.facebook.com/connect/login_success.html#access_token=", "");

				if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
				{
					at = url.Replace("http://www.facebook.com/connect/login_success.html#access_token=", "");
				}

				var accessToken = at.Remove(at.IndexOf("&expires_in="));

				return accessToken;
			}

			return string.Empty;
		}
	}

}


@LordDz
Copy link

LordDz commented Nov 14, 2017

I had trouble with this as well.

In the developer page for your app, go to Facebook Login->Settings.
In the Valid OAuth redirect URIs textbox, add http://www.facebook.com/connect/login_success.html

I made the mistake of using https:// It doens't work, make sure it's http://

@TranThiHang
Copy link

TranThiHang commented Nov 12, 2018

LordDz....I also have same trouble, but I changed the Valid OAuth redirect URIs to http://www.facebook.com/connect/login_success.html and not successfully because that URL is not allowed so I can't change...What have I to do now? help me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants