Null reference Error on AccessToken.CurrentAccessToken.UserID - facebook

Using Unity editor currently to test FB Login. Getting Null reference exception. Will login once if I clear registry of all session details.
Have tried some hotfixes previously found with SDK updates. This is an older sdk as the version of unity the game was written for was 5.3.3
private void initSession() {
Debug.Log("FbManager init session");
string logType = PlayerPrefs.GetString("LoggedType");
if (logType.Equals("Facebook")) {
GameManager.Instance.facebookIDMy =
AccessToken.CurrentAccessToken.UserId;
callApiToGetName();
getMyProfilePicture(GameManager.Instance.facebookIDMy);
LoggedIn = true;
Expect login to persist and be retrieved based on token stored in registry

Related

'Detection updating interface' in Unity3D Engine for Huawei AppGallery

How can I implement 'update interface' when a new app version is released based on Unity3D?
I have received this message from AppGallery review team : "We found that the detection updating interface isn't called in HMS after the app's startup".
The only documents that I have found is for implementing in Android studio in this link : Updating an App
After an app is launched or when a user proactively checks whether there is a later version, call the related API of the HMS Core SDK to check whether there is a later version available on AppGallery. If so, display a pop-up asking the user whether to update the app.
The key steps for achieving this function are as follows:
A user triggers an update check, for example, by launching the app or manually performing the check on the update check page.
The app calls JosApps.getAppUpdateClient to request to initialize the AppUpdateClient instance.
AppUpdateClient client = JosApps.getAppUpdateClient(this);
The HMS Core SDK returns the AppUpdateClient instance of the current app to the app.
The app calls the AppUpdateClient.checkAppUpdate method to request an update check.
public void checkUpdate() {
AppUpdateClient client = JosApps.getAppUpdateClient(this);
client.checkAppUpdate(this, new UpdateCallBack(this));
}
The HMS Core SDK queries the latest app version information on AppGallery.
AppGallery sends the app version information back to the HMS Core SDK.
The HMS Core SDK sends the check result to the app through a callback.
The app checks the ApkUpgradeInfo instance returned by the onUpdateInfo method in the callback result and checks whether an update is available.
private static class UpdateCallBack implements CheckUpdateCallBack {
private WeakReference<MainActivity> weakMainActivity;
private UpdateCallBack(MainActivity apiActivity) {
this.weakMainActivity = new WeakReference<MainActivity>(apiActivity);
}
public void onUpdateInfo(Intent intent) {
if (intent != null) {
MainActivity apiActivity = null;
if (weakMainActivity != null && weakMainActivity.get() != null){
apiActivity = weakMainActivity.get();
}
// Obtain the update status code. Default_value indicates the default return code when status cannot be obtained, which is determined by the app.
int status = intent.getIntExtra(UpdateKey.STATUS, DEFAULT_VALUE);
// Error code. You are advised to record it.
int rtnCode = intent.getIntExtra(UpdateKey.FAIL_CODE, DEFAULT_VALUE);
// Failure information. You are advised to record it.
String rtnMessage = intent.getStringExtra(UpdateKey.FAIL_REASON);
Serializable info = intent.getSerializableExtra(UpdateKey.INFO);
// Check whether the app has an update by checking whether info obtained is of the ApkUpgradeInfo type.
if (info instanceof ApkUpgradeInfo) {
// Call the showUpdateDialog API to display the update pop-up. The demo has an independent button for displaying the pop-up. Therefore, this API is not called here. For details, please refer to the checkUpdatePop() method.
if (apiActivity != null) {
apiActivity.showLog("There is a new update");
apiActivity.apkUpgradeInfo = (ApkUpgradeInfo) info;
}
}
if(apiActivity != null) {
apiActivity.showLog("onUpdateInfo status: " + status + ", rtnCode: " + rtnCode + ", rtnMessage: " + rtnMessage);
}
}
}
}
The app calls the AppUpdateClient.showUpdateDialog method to request to display the update pop-up for the user.
public void checkUpdatePop(boolean forceUpdate) {
AppUpdateClient client = JosApps.getAppUpdateClient(this);
client.showUpdateDialog(this, apkUpgradeInfo, forceUpdate);
Log.i(TAG, "checkUpdatePop success");
}
The HMS Core SDK displays the update pop-up for the user.
The user chooses to update the app on the update confirmation page.
The HMS Core SDK sends a request to AppGallery to download the latest app installation package.
AppGallery returns the app package to the HMS Core SDK. The HMS Core SDK starts to install the app after the download is complete.
For more details, pls kindly check this docs.

Firebase do not create user in Unity SDK

It is strange that Firebase can't create user in Unity SDK out of the box.
Firebase Console was tuned (anonymous access and email/password access are enabled) and google-service.json was placed in Assets folder of Unity.
However, Firebase still won't create a user. This is the code where it always fails:
auth.SignInAnonymouslyAsync().ContinueWith(task => {
if (task.IsCompleted && !task.IsCanceled && !task.IsFaulted) {
Debug.Log("User is now signed in.");
FirebaseUser newUser = task.Result;
}
else if (task.IsFaulted || task.IsCanceled)
{
Debug.Log("User signup failed");
}
});
Why?
There are possible several reasons:
The app was run in the Editor, rather than on the device
The configuration file is not updated after you add Firebase Auth feature
The password is shorter than 6 chacters
The email address is in invalid form, e.g. abcdef#aaa
The first one is highly likely the reason why.
I have created a tutorial here, which covers the steps to create/login using firebase in Unity, hope this is helpful.

Facebook UNITY SDK login issue

I just installed the new version of Unity 4.3 and the new facebook sdk and I can't get it working.
I created the app on facebook, copied over the app id to the unity facebook settings as required and copied the Package Name and Class name back to facebook.
Because the Android Key Hash is empty ( even it shouldn't be ) I used the methods posted by others to create one with openssl. I created it and copied over to facebook as required.
After this I created a small script to be able to login.
// Use this for initialization
void Start () {
enabled = false;
FB.Init(SetInit, OnHideUnity);
}
// Update is called once per frame
void Update () {
}
private void SetInit()
{
FbDebug.Log("SetInit");
enabled = true; // "enabled" is a property inherited from MonoBehaviour
if (FB.IsLoggedIn)
{
FbDebug.Log("Already logged in");
OnLoggedIn();
}
}
private void OnHideUnity(bool isGameShown)
{
FbDebug.Log("OnHideUnity");
if (!isGameShown)
{
// pause the game - we will need to hide
Time.timeScale = 0;
}
else
{
// start the game back up - we're getting focus again
Time.timeScale = 1;
}
}
void OnGUI(){
if (!FB.IsLoggedIn)
{
if (GUI.Button(new Rect(179 , 11, 287, 160), "Login to Facebook"))
{
FB.Login("email", LoginCallback);
}
}
}
void LoginCallback(FBResult result)
{
FbDebug.Log("LoginCallback");
Debug.Log("LoginCallback");
if (FB.IsLoggedIn)
{
OnLoggedIn();
}
}
void OnLoggedIn()
{
FbDebug.Log("Logged in. ID: " + FB.UserId);
}
Now when I click on the login button a Facebook window appears requesting permission, after I press ok, it returns, but I'm still not logged in... Can anybody help why is this?
Another strange thing I observed that the LoginCallback gets called as soon as I click on the login button, even though I would think it should only when I gave permission. Anyway when I give permission it returns to my app and nothing happens. I can click on the login button again and same thing happens, login callback called, it asks for permisions, I give the permision and returns back, nothing happened. Can anybody help?
Version 4.3.6 of the sdk should fix this problem. It's available here: https://developers.facebook.com/ We are still waiting for it to be approved on the asset store, so the only place to get it right now is from Facebook's site.
Note - it's still broken (5/2014) IF you use a Mac. Just follow the "Rafael solution", discover your hash properly from public void OnLoginComplete(string message). Cheers
So after being frustrated for a few days with having to trace out the key to my phone, I decided to look into what it was doing.
After some research it turned out that when you published to an android device, facebook would use the keystore that was defined in your publish settings, not your .android/debug.keystore file. So I went in and changed the sdk to make it work the proper way. Essentially I changed the SDK to look at the ProjectSettings instead of the debug directory for grabbing the key hash. In the FacebookAndroidUtils.cs I added the following.
// Using the user defined keystore values instead of the debug one.
degbugKeyHash = GetKeyHash( PlayerSettings.Android.keyaliasName, PlayerSettings.Android.keystoreName, PlayerSettings.Android.keyaliasPass, PlayerSettings.Android.keystorePass );
I created a small repo that provides the fix as well as some gui changes to make it more easy to update the key hash.
Github Facebook Unity SDK 6.1 Fix
Update - Fixed a bug with OS X related to escaping spaces on the string path
Hope this helps!
Take the "email" permission out of the login function and try it. Oops I thought I seen the "publish_actions" permission in there too.
Make sure the loginactivity in the manifest is in portrait.
Instead of implementing everything yourself, try using the free and open source SOOMLA Profile plugin for all of your social network needs:
https://github.com/soomla/unity3d-profile
Also available on the asset store for download:
https://www.assetstore.unity3d.com/en/#!/content/24601
It covers Facebook, Twitter and Google+ and has a unified API for logging in, posting statues, uploading images and getting friends lists. For proper disclosure, I'm one of the founders.

Check if facebook user is authenticated

I am building a helper class that would allow me to manage facebook account in a windows form application. I am using Facebook C# SDK. As it is suggested in its documentation, to know if the user is authenticated one would get the loginUrl
var loginUrl = oauth.GetLoginUrl(parameters);
and then afterward, navigate to that Url
webBrowser.Navigate(loginUrl);
Since I am on the back end of the application, I wonder how one can write a helper class that will return true or false to show if the user is authenticated or not. I would love to do something like:
public static bool IsUserAunthenticated (string appId, string[] extendedPermissions)
How can this function be written? Any ideas? Remember I am using windows form on .net 4.0
assuming this function is called some time after
webBrowser.Navigate(loginURL)
A solution like this could work:
assuming:
The user has already authorized your application
'facebookClient' is a static class field is already initialized
public static bool isUserAuthenticated() {
try
{
facebookClient.Get("/me");
//the lack of an exception thrown is a sign of success
return true;
}
catch (FacebookOAuthException e)
{
//your access token used to initialize 'facebookClient' is invalid
return false;
} }
Some general notes:
you didn't show any code to handle the retrieval of the actual access
token. I've been assuming you left that out for brevity.
passing in 'appID' and 'extendedPermissions' means that this method
would be used to REGISTER the user, not for testing to see if they
were already a user of your application.
related to the above point, you could pass in the access token as an
argument so you would be able to initialize 'facebookClient' inside
the method and run the authentication test.
To sum that last little bit up, if you're not already aware, you need to realize there are two distinct stages: getting the access token and using the access token.

Facebook C# sdk - Does the FacebookApp.Get("me") access to Facebook or just to cookie?

I'm using the Facebook c# sdk on a new project and i've a question.
In the follow code:
var app = new FacebookApp();
app.AppId = "myappid";
app.AppSecret = "theappsecretcode";
if (app.Session != null)
{
dynamic me = app.Get("me");
}
When i'm calling the method Get of FacebookApp, i'm i just accessing to the Cookie saved when i've authenticated with Facebook or i'm connecting to the Facebook and getting the values?
I'm asking because i'm saving the values of the user in a session when i authenticate with the Facebook, but if the method Get doesn't access to Facebook and just to the cookie, then i'll stop using the session and start to access to the Facebook cookie instead (i haven't understand yet if the cookie save some information about the user, but i've searched in "Watch" window in VS and i haven't found anything)
Thanks
I've examined source code of FacebookApp and FacebookAppbase classes and have found out that method Get is always accessing the Facebook (there is no any cache).