Facebook share in wp8 App - facebook

I need to share a message on Facebook in my windows phone App by clicking share button. when click share button , if user has not logged in to Facebook, first we redirect to log in screen and then need to ask permission to publish.
public partial class FacebookLoginPage : PhoneApplicationPage
{
string uriToLaunch ;
// Create a Uri object from a URI string
Uri uri = null;
public FacebookLoginPage()
{
InitializeComponent();
uriToLaunch = #"fbconnect://authorize?client_id={AppID}&
scope=public_profile,publish_actions,read_stream&
redirect_uri=msft-{ProductId}%3a%2f%2fauthorize";
uri = new Uri(uriToLaunch);
this.Loaded += FacebookLoginPage_Loaded;
}
private void FacebookLoginPage_Loaded(object sender, RoutedEventArgs e)
{
DefaultLaunch();
}
// Launch the URI
async void DefaultLaunch()
{
// Launch the URI
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
// URI launched
}
else
{
// URI launch failed
}
}
}
I used above code , but permission screen not appears for publish. Output was as follows.
I followed example and used an AppId, then it works well. I feel that there is special configuration in Facebook App side . Please help me If anyone have idea about it.

Related

Facebook login manual flow with error

After I dealt with this error a verified many fori and all mentioned that the solution for this error would be having in Facebook settings the “Valid OAuth Redirect URIs” set to “https://www.facebook.com/connect/login_success.htm”, what it is, so that is not the issue. Furthermore, all solutions found are too old and use obsolete components.
Said that using Xamarin Forms I’m trying to do the manual flow to login into Facebook as described in “https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow”.
The code is:
using Authentication.ViewModels;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Authentication
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class FacebookProfilePage : ContentPage
{
private string ClientId = "910688099117930";
public FacebookProfilePage()
{
InitializeComponent();
var apiRequest =
"https://www.facebook.com/dialog/oauth?client_id="
+ ClientId
+ "&display=popup&response_type=token&redirect_uri=http://www.facebook.com/connect/login_success.html"
+ "&state=state123abc";
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;
}
}
}
Please, notice that this is a open code, found in “https://github.com/HoussemDellai/Facebook-Login-Xamarin-Forms”, which historically has proven itself to work fine.
The URL that I send to login is: “https://www.facebook.com/v3.0/dialog/oauth?client_id=910688099117930&response_type=token&redirect_uri=http://www.facebook.com/connect/login_success.html”. I always get the error message: “Not Logged In: You are not logged in. Please login and try again.”.
Can anyone tell me what’s wrong here?
And before any comment, yes, I’ll delete this App Id as soon as the problem is solved and change it for a new one 😊

UBER with SSO using uber rides-android-sdk

I'm trying to get data from ALL_TRIPS Scope. I'm running into a few issues.
1) once I add the Scope.All_Trips to the .setScopes I get redirected verse being able to login to obtain the Token, therefore I get the necessary data from the get CurrentRide() method.
configuration = new SessionConfiguration.Builder()
.setClientId(CLIENT_ID)
.setRedirectUri(REDIRECT_URI)
.setScopes(Arrays.asList(Scope.HISTORY, Scope.PROFILE, Scope.RIDE_WIDGETS, Scope.ALL_TRIPS))
.setEnvironment(SessionConfiguration.Environment.SANDBOX)
.build();
validateConfiguration(configuration);
Error: Webpage not available The webpage at
Market://details?hl-en&id=com.ubercab&referrer=mat_cli%3
And it goes on and one.
Once i remove the All_TRIPS SCOPE I get the ability to Sign in.
Any help would be great so that I can move forward with getting the details like driver, vehicle, RideID.
private void LoadAllTrips(){
Session session = loginManager.getSession();
RidesService AllTrips = UberRidesApi.with(session).build().createService();
AllTrips.getCurrentRide().enqueue(new Callback<Ride>() {
#Override
public void onResponse(Call<Ride> call, Response<Ride> response) {
if (response.isSuccessful())
{
Toast.makeText(LoginSampleActivity.this, response.body().getRideId(), Toast.LENGTH_LONG).show();
}
else
{
ApiError error = ErrorParser.parseError(response);
Toast.makeText(LoginSampleActivity.this, error.getClientErrors().get(0).getTitle(), Toast.LENGTH_LONG).show();
}
}
#Override
public void onFailure(Call<Ride> call, Throwable t) {
}
});
}

Xamarin.Auth: Using Facebook oauth, how to redirect to my app?

I've just started using Xamarin.Auth and I want to enable Facebook login via oauth.
Here is my config:
public static string ClientId = "client id";
public static string ClientSecret = "client secret";
public static string Scope = "email";
public static string AuthorizeUrl = "https://m.facebook.com/dialog/oauth";
public static string RedirectUrl = "https://www.facebook.com/connect/login_success.html";
public static string AccessTokenUrl = "https://m.facebook.com/dialog/oauth/token";
Code for initiating the authentication:
public class AuthenticationPageRenderer : PageRenderer
{
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear (animated);
var auth = new OAuth2Authenticator (
Constants.ClientId,
Constants.ClientSecret,
Constants.Scope,
new Uri (Constants.AuthorizeUrl),
new Uri (Constants.RedirectUrl),
new Uri (Constants.AccessTokenUrl)
);
auth.Completed += OnAuthenticationCompleted;
PresentViewController (auth.GetUI (), true, null);
}
async void OnAuthenticationCompleted (object sender, AuthenticatorCompletedEventArgs e)
{
Debug.WriteLine ("AUTH Completed!");
if (e.IsAuthenticated) {
}
}
}
Seems to work fine, but instead of redirecting the user to https://www.facebook.com/connect/login_success.html, I want to redirect him back to my app again. Any help much appreciated!
Best,
Sascha
You can "redirect back" to your app again by simply invoking your own method to display the app's page you want to show to your user like this.
async void OnAuthenticationCompleted (object sender, AuthenticatorCompletedEventArgs e)
{
Debug.WriteLine ("AUTH Completed!");
if (e.IsAuthenticated) {
//invoke the method that display the app's page
//that you want to present to user
App.SuccessfulLoginAction.Invoke();
}
}
In your App.cs
public static Action SuccessfulLoginAction
{
get
{
return new Action(() =>
{
//show your app page
var masterDetailPage = Application.Current.MainPage as MasterDetailPage;
masterDetailPage.Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(MainPage)));
masterDetailPage.IsPresented = false;
});
}
}
Assuming that MainPage is the page you wanted to show after successful login. I am using Xamarin.Forms with MasterDetailPage to display pages in my example which maybe different from your app but the concept is the same.
Just call DismissViewController (true, null) in your OnAuthenticationCompleted method. Or use the async equivalent:
async void OnAuthenticationCompleted(object sender, AuthenticatorCompletedEventArgs e)
{
Debug.WriteLine("AUTH Completed!");
await DismissViewControllerAsync(true);
if (e.IsAuthenticated)
{
}
}

Codename one. Facebook login issues

I am having problem with facebook login in my cn1 app. I followed all the instructions given here: http://www.codenameone.com/facebook-login.html. I create a new instance of FacebookConnect then I set the clientId, secret etc. Then I set a LoginCallback and call doLogin(). However when I tried to run it on my device the screen just loads and it never stops. It doesn't even call LoginFailed. It just never stopped loading.
Here is my code:
faceBookButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
fb.setClientId("XXXXXXXXXXXXXXXX");
fb.setClientSecret("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
fb.setRedirectURI("");
fb.setCallback(new LoginCallback(){
#Override
public void loginFailed(String errorMessage) {
Dialog dg = new Dialog();
dg.setDisposeWhenPointerOutOfBounds(true);
dg.setTitle("Login succeeded");
dg.show();
}
#Override
public void loginSuccessful() {
String token = fb.getAccessToken().getToken();
Dialog dg = new Dialog();
dg.setDisposeWhenPointerOutOfBounds(true);
dg.setTitle("Login succeeded");
dg.show();
}
});
fb.doLogin();
}
});
Check out the full guide on facebook login here.
On login success you need to show a new Form and not a Dialog as you are moving away from the login screen of your application. There is a full end to end sample in the chat tutorial.

Not showing FB login screen

I am not able to show facebook login screen, i have downloaded facebook blackberry API https://sourceforge.net/projects/facebook-bb-sdk/,
but it shows me the current user of facebook, if there is no logged in user then it should open log in screen, but its not showing, i am using the below code:
To retrieve the current user (Synchronously):
User user = fb.getCurrentUser();
To retrieve the current user (Asynchronously):
fb.getCurrentUser(new BasicAsyncCallback() {
public void onComplete(com.blackberry.facebook.inf.Object[] objects, final java.lang.Object state) {
user = (User) objects[0];
// do whatever you want
}
public void onException(final Exception e, final java.lang.Object state) {
e.printStackTrace();
// do whatever you want
}
});
my problem is i want the face book login screen, when device does not have any face book user.
You are trying to get the current user asynchronously. Don't do that if you want to see the login screen. Do this instead:
Runnable a = new Runnable(){
public void run(){
ApplicationSettings as = new ApplicationSettings(YOUR_FACEBOOK_NEXT_URL, YOUR_FACEBOOK_APPLICATION_ID, YOUR_FACEBOOK_APPLICATION_SECRET, Facebook.Permissions.ALL_PERMISSIONS);
Facebook fb = Facebook.getInstance(as);
try {
User user = fb.getCurrentUser();
if( user != null){
//do whatever
}
} catch(FacebookException e){
//Crazy happened!
}
}
};
UiApplication.getUiApplication().invokeLater(a);
I think this should solve your problem. Cheers.