Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Facebook SDK for Unity - Plus Windows Phone 8

Discussion in 'Windows' started by zeezeezee, Dec 17, 2013.

  1. zeezeezee

    zeezeezee

    Joined:
    Aug 6, 2013
    Posts:
    20
    $facebook-sdk.png
    ***Updated****

    Hey folks,

    Facebook Plugin for Unity with Windows Phone 8 support version 2.0. Yes, it’s still Free! Now your login is done through the Facebook App and the login is valid for more then 30 days! If you don't have the app it asks if you want to download it.

    I’ve provided the Source code for the Windows Phone 8 Login DLLs, both fake and real, in case you want to make changes.

    Download the Unity Package here: https://bitbucket.org/chillsters/facebook-unity-sdk-with-wp8/src

    NOTE: Use with caution! I have tested it but your game could crash.
    The plugin is the same Facebook SDK plugin developed by Facebook but extended with Windows Phone 8 login capabilities. All the functions and method calls are the same only difference is the addition of the extra files.


    So use the same function calls as you would on iOS or Android. But you still need to do some things to enable login on Windows Phone 8.

    The plugin is made from the latest plugin available (v 4.3.6, build: 131121.1756) dated Dec 02, 2013.

    1. Import Build Visual Studio Project in Unity.

    Build your Unity project. Just like be sure to follow that steps setting up the Facebook App values; i.e App ID and App Name.

    2.1 Edit your project App Manifest.

    Configure your app’s manifest file (WMAppManifest.xml) to register a custom uri scheme that is of the form msft-{ProductID}, where {ProductID} is your app’s product ID (without dashes). Add the text after <Tokens>. It should look like this:

    Code (csharp):
    1.  
    2. <Extensions>
    3.             <Protocol Name="msft-f3bde1f120174f3c8ad9ad53098243e2" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" />
    4. </Extensions>
    5.  
    Important note: If you have not yet submitted your app to the Windows Phone Store, be aware that the product ID used during development is a randomly assigned placeholder. After your app has been certified, it has a different product ID. In this case, submit your app first to get a product ID assigned, but select the Manual publish option to ensure that you don’t release an app that is not set up correctly on the Facebook Developers site. Once you have your final product ID, make sure you update your WMAppManifest.xml to Use the final product ID rather than the randomly assigned placeholder.

    Add ActivationPolicy="Resume" to your Default Task. It should look like this:

    Code (csharp):
    1.  
    2.  <Tasks>
    3.       <DefaultTask Name="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume"  />
    4. </Tasks>
    5.  
    Note: If you do not add this property your game will restart everytime you try on login.

    2.3 Update your app on the Facebook Developers site

    You also need to enter some information about your app in the Facebook Developers site, for example, identify your application ID in the Windows Phone Store so Facebook can ensure only your app gets access tokens granted by users to your Facebook app.

    1. Go to http://developers.facebook.com and log in.
    2. Click Apps in the top navigation bar.
    3. Select your Facebook app in the left pane (or create a new one if you are starting from scratch).
    4. Click edit settings.
    5. Under select how your application integrates with Facebook, find the section for Windows App and expand it.
    6. Enter exactly the same product ID you entered in your WMAppManifest.xml file, the {ProductID} portion (without dashes) of your msft-{ProductID} custom URI scheme.


    Important note: See earlier note on how the product ID is different during development and after submission. This is crucial if you have not yet been assigned a product ID.

    Here’s an example of how the Facebook Developers site looks when set up.

    $image_5F00_thumb_5F00_27E606D0.png

    That’s it!

    Be careful when using the Login() Logout() functions though. Calling them close together can cause your app to crash.

    Download the Unity Package here: https://bitbucket.org/chillsters/facebook-unity-sdk-with-wp8/src

    It would be nice if Facebook was paying me to keep this plugin up to date. So I'll try my best.



    $logo.png

    You can support us by downloading Pigs Can't Fly. http://www.chillsters.com/pigscantfly
     
    Last edited: May 1, 2014
  2. zeezeezee

    zeezeezee

    Joined:
    Aug 6, 2013
    Posts:
    20
    (Update #1: Fixed Compile bug for Windows Phone 8, caused by FB.cs and FB.Screen.cs)
     
  3. zeezeezee

    zeezeezee

    Joined:
    Aug 6, 2013
    Posts:
    20
  4. BraveVN

    BraveVN

    Joined:
    Jun 12, 2013
    Posts:
    21
  5. kaiber

    kaiber

    Joined:
    Mar 4, 2013
    Posts:
    15
    Any chance of getting this working with the latest version of the Facebook Unity SDK?
     
  6. BraveVN

    BraveVN

    Joined:
    Jun 12, 2013
    Posts:
    21
    at the end of #1:
    I think Window Phone community should pay him to keep this plugin up to date :) we must do it by ourselves :)
     
  7. Mahdi-Jeddi

    Mahdi-Jeddi

    Joined:
    Dec 21, 2012
    Posts:
    27
    There is a bug in WindowsPhoneFacebook.cs line 177:

    Code (CSharp):
    1. if(_link.Length > 0) url += "&link=" +_toId;
    Should be:
    Code (CSharp):
    1. if(_link.Length > 0) url += "&link=" + _link;
     
  8. Mahdi-Jeddi

    Mahdi-Jeddi

    Joined:
    Dec 21, 2012
    Posts:
    27
    I fixed another problem; when the user logs in and the second time he wants to use the app, you check the saved token in CheckAccessTokenValid() function. But usually it freezes. I solved this by running the code in another thread like this:
    Code (CSharp):
    1.                 System.Threading.ThreadPool.QueueUserWorkItem(delegate
    2.                 {
    3.                     string url = "https://graph.facebook.com/" + UserID + "?access_token=" + AccessToken;
    4.                     Uri uri = new Uri(url);
    5.                     HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
    6.                     request.BeginGetResponse(new AsyncCallback(ReadCallback),
    7.                     request);
    8.                 }, null);
    9.  
     
  9. SyncInteractive

    SyncInteractive

    Joined:
    Mar 17, 2014
    Posts:
    12
    Hi

    Firstly thank you for the time and effort you have put in to prepare this plugin.

    Im only interested in the Windows section and have run into an issue with the login. I can't seem to ever login successfully the login view appears fine and it redirects back to the app but the value for FacebookWP8.IsLoggedIn is always false.

    Thanks
     
  10. kaiber

    kaiber

    Joined:
    Mar 4, 2013
    Posts:
    15
  11. andrescavallin

    andrescavallin

    Joined:
    Mar 29, 2014
    Posts:
    11
    Hello, Mahdi or Zee
    My app crashes when resuming back from Facebook app to my game. I know it fails during the Login process but don't have any idea how to debug.

    I want to try Mahdi proposed fix but I don't know how. I downloaded the source code for FacebookWinPhone8.dll, made the change and replaced the DLL directly in the Visual Studio project that Unity generated. But then my game crashes on start, I tried compiling for Release | ARM and Any Release | Any CPU

    Thanks very much for having created this tool
     
    Dapperapps likes this.
  12. Dapperapps

    Dapperapps

    Joined:
    Jun 12, 2014
    Posts:
    9
    Seconded andrescavallin's post.
    We are receiving the following exception:


    An unhandled exception of type 'System.IO.FileLoadException' occurred in System.Windows.ni.dll
    Additional information: Could not load file or assembly 'IFacebook, Version=0.0.0.0, Culture=neutral, PublicKeyToken=d9f0385cc69e16d8' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
     
  13. tkoknordic

    tkoknordic

    Joined:
    Jan 31, 2013
    Posts:
    93
    Exactly same problem here! Is there another plugin you can use or what are my options with WP8 + FB?
     
  14. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    Same problem for me as well - what version of Unity are you guys using? I've just updated to 4.5.2 and wondering if its related?

    I'm going to downgrade and see if it still works
     
  15. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    Works if you downgrade :)
     
  16. andrescavallin

    andrescavallin

    Joined:
    Mar 29, 2014
    Posts:
    11
    I downgraded from 4.5.2 to 4.5.1f3 and solved the unhandled exception problem.
    To solve the first problem I posted, about crashing when returning from Facebook App, I followed Mahdi's two suggestions.
    I was able to make this changes by opening the project from Visual Studio: FILE -> Add -> Exiting Project…, navigate to Unity project folder and select Assembly-CSharp.csproj file and looking for the code...but I think It also might be changed directly on Unity/Mono Develop by opening Assets\Facebook\Scripts\WindowsPhoneFacebook.cs
    Sadly I had reported a Unity 4.5.1 bug for capturing screenshots using Texture2D.ReadPixels on my Nokia Lumia that may be solved in future versions and now I can't upgrade to see if this was fixed on 4.5.2 . If I come with a solution I will let you know.
     
  17. latas

    latas

    Joined:
    Oct 9, 2013
    Posts:
    149
    I'm doing a basic test for a simple post. As I know for a simple post is not needed to ask for approval, so you can use it as it is. I did it for iOS, and Android with success. The same code for Windows Phone, looks does not authenticate to me. Can anyone provide me some lines of code of the authentication and login part you use with success for WP8. Thank you very much.
     
  18. andrescavallin

    andrescavallin

    Joined:
    Mar 29, 2014
    Posts:
    11
    Hello Latas, I can provide a sample code but I use the exact same code for all platforms including iOS, Android, Web and WP8. The difference is within the SDK, not on how you use it.
    Please double check steps 2.1 and 2.3 at the beginning of this post, since once you have it running for iOS and Android the same code will work for WP8 assuming you did those steps and also assuming you are using this SDK instead of the Facebook's one.
    If you need help finding the specific reason for why the POST is failing, check out this post:
    http://stackoverflow.com/questions/...-a-users-score-through-facebook-sdk-for-unity
     
  19. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168

    I've started getting this since fixing the compile issue. the moment I click on my Login with Facebook button, it fails with an SEHException, which then makes the whole thing fail. It doesn't crash out completely, but if you're running in debug, it gives you a call stack. I have Mahdi's changes in the DLL's and recompiled them, but I get the same problem. Here's the call stack after the exception:

    Code (csharp):
    1.  
    2. Exception: External component has thrown an exception.
    3. Type: System.Runtime.InteropServices.SEHException
    4. Module: UnityEngine
    5. InnerException: <No Data>
    6. AdditionalInfo:<No Data>
    7.    at UnityEngine.Internal.$Calli.Invoke90(Int32 arg0, Int64 arg1, IntPtr method)
    8.    at UnityEngine.MonoBehaviour.StartCoroutine_Auto(IEnumerator routine)
    9.    at UnityEngine.MonoBehaviour.StartCoroutine(IEnumerator routine)
    10.    at Facebook.WindowsPhoneFacebook.Login(String scope, FacebookDelegate callback)
    11.    at LoginManager.FacebookLogin()
    12.    at tk2dUIItem.Release()
    13.    at tk2dUIManager.CheckInputs()
    14.    at tk2dUIManager.Update()
    15.    at tk2dUIManager.$Invoke30(Int64 instance, Int64* args)
    16.    at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
    Any ideas?
     
  20. Para-bellum

    Para-bellum

    Joined:
    Aug 7, 2013
    Posts:
    3
    Hello. I add canvas url https://www.google.com/, and same in advanced Valid OAuth redirect URIs . I get an error on windows phone after i trying to login -"Invalid redirect URI, please refer to Facebook login documentation". Can someone help me?
     
  21. latas

    latas

    Joined:
    Oct 9, 2013
    Posts:
    149
    When I call to do the login, the Facebook App appears. I agree with permissions. But it looks after back to the game, I check if user is logged in, to hide the button connect, and show a SHARE button. That never works. It looks I'm still not authenticated. Any idea why?

    It works in iOS and
     
  22. latas

    latas

    Joined:
    Oct 9, 2013
    Posts:
    149
    But, how to test it? I mean, my App is approved in Windows Phone Stored. But still it hasn't activated FB support. Now in my development test I've implemented FB. So I think, to do a simple post it is not necessary you send the app to review in Facebook, but do you need anything else to test this? My fault, is I've never been authenticated.
     
  23. andrescavallin

    andrescavallin

    Joined:
    Mar 29, 2014
    Posts:
    11
    Latas, yes you can test without approval from FB as long as you use the developer account, in which case only you will see the posted content. Now, I understand it is working on iOS, so it is not the code that is failing. The same code that worked on iOS should work on WP8. Did you do step 2.1 and step 2.3?
     
  24. andrescavallin

    andrescavallin

    Joined:
    Mar 29, 2014
    Posts:
    11
    This fix is really needed. Since I struggled to get it done, I want to advise that you need to modify the source code of the FacebookWinPhone8.dll in order to have this fix incorporated in your code. Bear in mind that there is a Fake DLL and a Real DLL, and that after you make the change on the Real DLL project, you need to clear (empty both DLL and .meta files) and copy the newly compiled DLL in the folder named \Assets\Plugins\WP8
     
  25. latas

    latas

    Joined:
    Oct 9, 2013
    Posts:
    149
    The product ID I get because of my App is already published or the product ID you get while developing? Because if I'm trying to setup in Visual Studio the msft-XXXXX with the temp product ID code, then that line is underlined as an error, and I can not use it. So I'm using the published product ID code. I setup that code in the Facebook Apps section. But I guess my development compilation while I'm testing is not using that code, because still I didn't submit the facebook changes. Maybe I'm using a product ID which is not the one I should use. But I followed the instructions and I guess I'm not wrong.

    Thank you.
     
  26. globalyst

    globalyst

    Joined:
    Aug 7, 2014
    Posts:
    2
    My game continue crashing when returning from Facebook App after to add Mahdi's changes.
    I have next error:

    El programa '[3948] TaskHost.exe' terminó con código -1073741819 (0xc0000005) 'Access violation'.

    The error is random, sometimes return to app and login, but others crash(2/3).

    Some idea?
    Thx.
     
    Last edited: Aug 7, 2014
  27. nepcono

    nepcono

    Joined:
    Aug 5, 2014
    Posts:
    9
    I have Unity 4.5.2f1 and when using the plugin the app crashes on start-up what can be the problem.

    I read this thread, and found out that downgrading Unity should work but this is not an option
     
  28. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    Upgrading to 4.5.3 should fix your problem now.
     
    SamKO likes this.
  29. latas

    latas

    Joined:
    Oct 9, 2013
    Posts:
    149
    I've read, there is a new Facebook release for WP8 delivered on August, 1st. Anyone knows something about it?

    Thanks.
     
  30. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
  31. nepcono

    nepcono

    Joined:
    Aug 5, 2014
    Posts:
    9
    Hey the SDK Plus wp8 does not work anymore after the Facebook SDK 6.0 release
     
  32. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    Doesn't surprise me. I'm not sure Zee is around anymore. I'll see if I can update it. I'd suggest you stick to 5.1 though until the this library is updated or Facebook get around to giving us WP8 support.

    If you really need some of the features of Facebook 6.0, you're gonna have to just hang fire unfortunately.
     
  33. nepcono

    nepcono

    Joined:
    Aug 5, 2014
    Posts:
    9
    we did not change anything at our Windows Phone build. after the update to Facebook 6.0 is does not work anymore.
     
  34. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    It may be that the IFacebook.DLL has changed in 6.0. Are you getting any exceptions or anything to track down the cause?
     
  35. nepcono

    nepcono

    Joined:
    Aug 5, 2014
    Posts:
    9
    I really do not know what is happening ?
     
  36. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    I'll see if there is anything I can do to make it work.

    As I said earlier though, is there a specific reason you're wanted 6.0? Is there a feature in there you're after using or a bug in 5.0 that 6.0 fixes? If no, stick with 5.0. There is absolutely no harm in it for now unless Facebook force the issue. Which as 6.0 has only just come out and 4.x is still supported, I don't think that's anything to worry about.
     
  37. nepcono

    nepcono

    Joined:
    Aug 5, 2014
    Posts:
    9
    I only noticed that the DLL facebook is not loaded from SDK 5.1 when targetting Windows Phone 8 or Windows Store
    It worked but not anymore.
     
  38. nepcono

    nepcono

    Joined:
    Aug 5, 2014
    Posts:
    9
    when i start a blanc project import the FaceBookSDKPlusWP8.
    Select scene interactive console (default PC) the dll is loaded calling FBInit;
    however when I select Windows Phone or Windows Store the same call FBInit the dll is not loaded

    It worked before Facebook updated to SDK 6.0 from one on the other day it stopped working.
     
  39. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    have you updated your SDK to 6.0 or downloaded from the links above?
     
  40. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    I've just done a new release of my game on Windows Phone and Facebook login definitely works fine.
     
  41. nepcono

    nepcono

    Joined:
    Aug 5, 2014
    Posts:
    9
    Nope I did not update only used the unity package with 5.1 version.

    Windows Phone 8.1 can that be the problem. I really do not understand why it is not working.

    Can you post me a snippet with login because I need to login over and over again.

    It did work, it stopped working after the Facebook internal update to SDK 6.0 or when I updated my Windows Phone to 8.1
     
  42. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    hmm, I have users on Windows Phone 8.1 and using this SDK and I have no problems. You're best off running your build in Debug mode in Visual Studio and turn on CLR Exception throwing. This can be found by going Debug->Exceptions then tick the thown box by CLR Exceptions.

    Hopefully this will give you some more details either from the error log or where Facebook is failing internally. If you can do that and let me know, I might be able to track it down a bit more.

    Thanks,

    Alan
     
  43. NigmaLab

    NigmaLab

    Joined:
    Aug 30, 2014
    Posts:
    7
    Hi,

    I'm having problems using the same codebase for Windows 8 store apps. Does anyone know if there is a way to exclude the facebook SDK when exporting to Windows store apps?

    Thanks!
     
  44. nepcono

    nepcono

    Joined:
    Aug 5, 2014
    Posts:
    9
    Hi, did turn on the CLR exceptions within Visual Studio 2013. But no results no errors.

    What is happening :

    button when user clicks on it, to share score
    Facebook login is shown
    app is resuming

    I really dont understand what is happening. it worked like a charm, but suddenly it stopped working.
     
  45. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    @NigmaLab - While the FakeDLL will be included in your Windows Store app, there is no RealDLL and so there shouldn't really be a problem with that. What happens when you try to export to Windows Store? I've had this working and got Facebook login working for Store as well (Only component I use from Facebook, I don't use sharing)

    @nepcono - Does you app fully resume, but not authenticating you? I have seen this before and I've handled it by checking the response and calling login again. Not the best solution, but as your app will already be authorised by Facebook, it just pops up the Facebook app again then resumes yours. It usually passes on the 2nd attempt. This may be something to do with the new 2.0 Graph API rather than SDK 6.0
     
  46. nepcono

    nepcono

    Joined:
    Aug 5, 2014
    Posts:
    9
    @Kujo87 - First you get Facebook authentication, after that it resumes the app (resuming...) but nothing happens it does not log in. Authenticate window is showen all over again.
     
  47. NigmaLab

    NigmaLab

    Joined:
    Aug 30, 2014
    Posts:
    7
    @Kujo87 I get a filenotfound exception when loading the app in Windows8. But after further investigation it seems that your plugin works fine, it's the official 6.0 throwing the exception. Is there no FakeDLL included in the official SDK?
     
  48. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    No, Windows is not officially supported by Facebook at all yet, so you won't be able to use the official 6.0 SDK. All of their stuff is beta at the moment for Windows, and there is no Unity plugin available yet. The plugin here isn't written by me, its from the guys at Chillsters, but I've been using it for a while now and extended it to work on Windows Store as well, so I know pretty well how to use it.
     
  49. Kujo87

    Kujo87

    Joined:
    Sep 16, 2013
    Posts:
    168
    What happens if you just try to do a login rather then the sharing feature? As I say, I don't actually use the sharing in my app, so I can't say whether it breaks on mine either. I just use this for Login.

    Worth a shot, just make your button call FB.Login("publish_actions", FacebookLoginCallback); and put some kind of handler in there and see what you get. It might be something with the sharing thats the problem. This will help to narrow it down
     
  50. jojo665_

    jojo665_

    Joined:
    Feb 16, 2014
    Posts:
    4
    @Kujo87 would you mind to share how you get this to work in Windows Store platform ? bc seems like some of the API does not exist in WSA platform ? like "Application.Current.RootVisual" in FacebookWP8 class ?

    thanks