Not showing FB login screen - facebook

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.

Related

Facebook Login with Unity 5 - Always return me Graph API Error: Bad request

I just start write my first game with unity.
I Created on facebook app - in games category.
I downloaded Facebook idk and added to unity.
I changed app id in Facebook settings.
Now I tried my code:
public class LoginScript : MonoBehaviour {
public string resultstr { get; set; }
public Text LableResult { get; set; }
List<string> perms = new List<string> (){"public_profile", "email", "user_friends"};
// Use this for initialization
void Start () {
LableResult = gameObject.GetComponent<Text> ();
LableResult.text = "Test";
if (!FB.IsInitialized) {
// Initialize the Facebook SDK
FB.Init (InitCallback, OnHideUnity);
} else {
// Already initialized, signal an app activation App Event
FB.ActivateApp ();
}
}
private void InitCallback ()
{
if (FB.IsInitialized) {
// Signal an app activation App Event
FB.ActivateApp ();
// Continue with Facebook SDK
// ...
} else {
Debug.Log ("Failed to Initialize the Facebook SDK");
}
}
private void OnHideUnity (bool isGameShown)
{
if (!isGameShown) {
// Pause the game - we will need to hide
Time.timeScale = 0;
} else {
// Resume the game - we're getting focus again
Time.timeScale = 1;
}
}
// Update is called once per frame
void Update () {
}
private void AuthCallback (ILoginResult result)
{
if (FB.IsLoggedIn) {
// AccessToken class will have session details
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
// Print current access token's User ID
Debug.Log (aToken.UserId);
// Print current access token's granted permissions
foreach (string perm in aToken.Permissions) {
Debug.Log (perm);
}
} else {
Debug.Log ("User cancelled login");
}
}
// On Facebook login button
public void OnFacebook ()
{
FB.LogInWithReadPermissions (perms, AuthCallback);
}
}
But I'm ALWAYS getting in Result:
Graph Api Error: 400 Bad request
And callback_id 2 (sometimes I've seen 3)
Login I try in Mock window with token from facebook.
I tried deploy on iPhone - and game just crashed when I click on login button
Please to close this topic. I fixed it. It was my fail )) (Used app token instead user token )) (Happends)))))
The same thing happened to me!
Remember to check the user token part, which won't be set by default!

Facebook publish_actions aproved but grantedScope shows publish_actions only for me

I'm having an interesting issue.
My FB Canvas game is in dev mode and i have gotten my publish_actions approval. When launch my game in the browser i get the list of grantedScopes when logged into my account it lists publish_actions correctly and everything works, but when one of my testers (i have given the person the tester roll in the fb dev console.) Loads up the game then it does not list publish_actions under their grantedScopes.
Am i doing something wrong?
Do I need to request of the user to accept this new permission somehow?
here is my fblogin code
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Facebook.Unity;
using UnityEngine.UI;
using System;
public class FBLogin : MonoBehaviour {
void Awake()
{
FB.Init (SetInit, OnHideUnity);
}
private void SetInit()
{
Debug.Log ("FB Init done.");
if (FB.IsLoggedIn)
{
Debug.Log ("FB Logged In.");
}else{
Debug.Log("FB NOT Logged In.");
}
}
private void OnHideUnity(bool isGameShown)
{
if(!isGameShown)
{
Time.timeScale = 0;
}else{
Time.timeScale = 1;
}
}
public void FBlogin ()
{
var perms = new List<string>(){"public_profile", "email",};
FB.LogInWithPublishPermissions(perms, AuthCallback);
}
private void AuthCallback (ILoginResult result)
{
Debug.Log(result.RawResult);
if (FB.IsLoggedIn)
{
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
// Print current access token's User ID
Debug.Log(aToken.UserId);
// Print current access token's granted permissions
foreach (string perm in aToken.Permissions) {
Debug.Log(perm);
}
} else {
Debug.Log("User cancelled login");
}
}
}
Thanks guys.
The permissions you are requesting are not publish permissions, they are read permissions. You will need to use
FB.LogInWithReadPermissions(new List<String>(){"public_profile", "email"}, AuthCallback)
to log in with the requested read permissions. Once your callback fires, you will need to submit a second request:
FB.LogInWithPublishPermissions(new List<String>(){"publish_actions"}, AuthCallback)
You cannot combine read and publish permissions on the same request dialog to the end user. Rather than open two dialogs back to back, it is considered best practice to hold off on requesting the publish permissions until the user actually attempts to publish something from within your app.

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.

Facebook share in wp8 App

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.

logout facebook connect session

I'm trying to integrate my site with facebook connection to handle facebook signup and facebook login. i'm using codeigniter framework. But I got this problem now:
current facebook login user is "test1". I go to my site to sign up with facebook, everything works fine and "test1"'s info are stored in my database. However, after I log test1 out from facebook, and login "test2" in on facebook, I go back to my site and do a signup with facebook again, it still "test1"'s info stored.
I use ion auth library to handle user logout from my site. However, after I switch facebook test user accounts and do a "login with facebook" again, it still get the previous facebook user.
Based on the 2 cases above, it seems that the facebook session wasn't cleared up? I'm struggling on this problem for a long time, please help!
I user this to get user data:
$fb_usr = $this->fb_connect->user;
(it seems that no matter how the facebook user changs, fb_connect always return same user)
and fb_connect is sth like this:
<?php
include(APPPATH.'libraries/facebook/facebook.php');
class Fb_connect extends Facebook{
//declare public variables
public $user = NULL;
public $user_id = FALSE;
public $fbLoginURL = "";
public $fbLogoutURL = "";
public $fb = FALSE;
public $fbSession = FALSE;
public $appkey = 0;
//constructor method.
public function __construct()
{
$CI = & get_instance();
$CI->config->load("facebook",TRUE);
$config = $CI->config->item('facebook');
parent::__construct($config);
$this->user_id = $this->getUser(); // New code
$me = null;
if ($this->user_id) {
try {
$me = $this->api('/me');
$this->user = $me;
} catch (FacebookApiException $e) {
error_log($e);
}
}
if ($me) {
$this->fbLogoutURL = $this->getLogoutUrl();
} else {
$this->fbLoginURL = $this->getLoginUrl();
}
} //end Fb_connect() function
}
I think what you need to do is set the "next" param for your getLogoutUrl() call. Something like this:
$args['next'] = site_url('logout'); // replace "logout" with your controller which will clear the session
$fbLogoutURL = $facebook->getLogoutUrl($args);
Then, in the controller set as "next" you'll need to clear the session data.
class Logout extends CI_Controller {
public function index() {
$facebook->destroySession();
$this->session->sess_destroy(); // Assuming you have session helper loaded
$this->load->view('logout');
}
}
Let me know if that helps.