Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Closed] Social Networking Plugin (Facebook and Twitter) live!

Discussion in 'iOS and tvOS' started by prime31, Sep 19, 2010.

  1. Ale-Farinella

    Ale-Farinella

    Joined:
    Jul 7, 2012
    Posts:
    7
    @prime thanks very much. There's any way to activate location detection in the facebook composer in ios6 and to change the default "IOS Photos" album name with one i decide for example the name of my app, using your plugins ?

    I am also a little bit confused. I uploaded to 1.5.5 but i can't find any reference to the following method and the other you have added. I delete the files before updating. still in facebookbinding.cs can't find the methods.
    When i add FacebookBinding.reauthorizeWithPublishPermissions... i get : unresolved member ...

    From your website:
    // Reauthorizes with the requested publish permissions and audience
    public static void reauthorizeWithPublishPermissions( string[] permissions, FacebookSessionDefaultAudience defaultAudience )

    what i am doing wrong ?

    Thanks
    Ale
     
    Last edited: Sep 29, 2012
  2. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ale, you probably don't have the latest version of the plugin. If you purchased it from the Asset Store it often takes a few days to show up.
     
  3. Ale-Farinella

    Ale-Farinella

    Joined:
    Jul 7, 2012
    Posts:
    7
    @prime thanks . which is the latest ? 1.5.?
     
  4. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ale, open the Asset Store to see that latest version that Unity has approved.
     
  5. trop

    trop

    Joined:
    Sep 5, 2012
    Posts:
    41
    hi prime31! your plugin is great!everything in my application is cool,working so far after a long long decade,hehe, one more thing i wanna ask you about,.

    im having problem with the flow,.can you teach me how to put the methods to correct my flow. when i clicked the button login it directs me to facebook login, but once user loggedin it jst stops there, it didnt direct the user into the permission. and didnt go back to the game app., heres my code:

    void Start()
    {
    FacebookBinding.init( "55704355887" );
    isLoggedIn = FacebookBinding.isSessionValid();

    // Dump custom .data to log
    FacebookManager.customRequestReceivedEvent += result =>
    {

    var permissions = new string[] { "publish_actions", "user_games_activity" };
    FacebookBinding.loginWithRequestedPermissions( permissions );

    ResultLogger.logObject( result );
    Debug.Log(result);
    };


    if (!isLoggedIn)
    {

    Debug.Log ("USER NEEDS TO LOGIN!");
    }

    else
    {



    }
    }

    void Update()
    {
    if (Input.touchCount == 1){

    if (Input.GetTouch(0).phase == TouchPhase.Began)
    {
    var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
    RaycastHit hit;

    if (collider collider.Raycast (ray, out hit, 100.0f)){

    onTapHit();
    }

    if(FacebookBinding.isSessionValid())
    {
    //proceedUserInfo();
    onTapHit();

    }

    }

    }
    }

    // common event handler used for all graph requests that logs the data to the console
    void completionHandler( string error, object result )
    {
    if( error != null ){
    Debug.LogError( error );}
    else{
    ResultLogger.logObject( result );
    }
    }

    void onTapHit()
    {
    UnityEngine.Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

    RaycastHit hit;

    if (Input.GetMouseButton (0)){

    if (Physics.Raycast (ray, out hit)){

    string objName = hit.collider.gameObject.name;

    if (objName == "loginBTN"){


    var permissions = new string[] {
    "publish_actions",
    "user_games_activity",
    "user_photos",
    "user_videos",
    "publish_stream",
    "manage_notifications",
    "read_stream",
    "read_friendlists"

    };
    FacebookBinding.loginWithRequestedPermissions( permissions );
    }



    }
    }


    }
     
  6. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,740
    Hi

    I downloaded the sept 27 update but it crashes on the system. First, the generated .h files on Xcode have problems. I tried removing the plugin and reinstalling and it will fail to compile. I had to manually add import fbrequest registration.h files to 2 of them.

    Also, when I hit run, on login it fails. It had the old token from the previous version but it says the token is not valid so I call the login method which spills this out on the xcode
    Facebook login failed: The operation couldn’t be completed. (com.facebook.sdk error 2.)

    I have no idea why it fails, the dialog doesn't even come up.
     
    Last edited: Oct 1, 2012
  7. woko

    woko

    Joined:
    Oct 11, 2011
    Posts:
    23
    I also have problems with the sept 27 version; xcode 4.5 won't compile because some header files are not included? (FacebookManager.mm:284:3: Use of undeclared identifier 'FBRequestConnection' etc)
     
  8. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @trop, if your app is not being reopened by Facebook you did not properly setup the URL scheme in the info.plist or your app is not properly setup on Facebook's website. Double and tripple check those items.


    @creat327, armv6 support was dropped and will no longer work. I would suggest that you import the plugin into an empty Unity project so that you can confirm that all is working fine and you have no conflicts.


    @woko, performing the following steps results in an app the compiles fine for us:
    - create empty Unity project
    - download latest version of the plugin and import it
    - setup URL scheme
    - build
     
  9. SilentWarrior

    SilentWarrior

    Joined:
    Aug 3, 2010
    Posts:
    107
    I have the same problems. After importing (deleted all the files from your plugin inside unity and reimported), deleted the xcode project completely, did a build, when xcode opens, i get build errors.

    I could be useful for you guys to provide us with instructions and/or settings inside unity that enable the new plugin version to work.
     
  10. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @silent, there is no magic way to get Unity to work with updates. Sometimes new files just don't get copied over when importing the unitypackage. If you follow along with the release notes and delete all old files before importing the new ones you should never run into any issues. Of course, whenever you change files you should also run the Clean command on your Xcode project.
     
  11. SilentWarrior

    SilentWarrior

    Joined:
    Aug 3, 2010
    Posts:
    107
    Here is how i solved it :

    On Xcode, click the Folder icon on the left (project files), open Frameworks, and on libfacebook_ios_sdk.a right click, Delete->Remove Reference, it should also show a "?" icon on the right of the name, so you know what is the correct one to remove.

    Edit : Well, it solved the compile time error. However, I now get a runtime error (fatal crash) each time i try to login. If I keep "libfacebook_ios_sdk.a" and remove "libFacebookSDK.a" instead, it will throw the old white page on login, but no runtime fatal crash.

    What do I do here ?

    PS: all this with the default scene you provide
     
    Last edited: Oct 1, 2012
  12. SilentWarrior

    SilentWarrior

    Joined:
    Aug 3, 2010
    Posts:
    107
    I tried the same, it builds just fine for me too, but when i click login in your test scene, all i get is a blank page. It doesnt go to facebook.
     
  13. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @silent, you still have to properly setup your Facebook app ID and URL scheme. Nothing will happen without that information.
     
  14. woko

    woko

    Joined:
    Oct 11, 2011
    Posts:
    23
    Thanks, deleting the old files helped. It looks like importing a new version of the package is indeed rather buggy.
     
  15. SilentWarrior

    SilentWarrior

    Joined:
    Aug 3, 2010
    Posts:
    107
    Yes. What I did was delete Library folder, delete Xcode folder, delete the plugin, reimport everything, setup everything, build, delete both facebook libs refereces, download 3.1 sdk and import that, remove facebook app from my ipod (was causing white login screen somehow), build and test, and everything seems to work.


    Right now I am stuck on the new login stuff. My app uses a single button for posting an image to facebook. Before, i would check if the session was valid, if not, then it would login, and the loginsuccessful would call the post image, if session was valid, just post image.

    However now, first if session is not valid, login with the permitions set for "email", then set the onsucessfullogin event to call yet another permitions thing with "reauthorizeWithPublishPermissions", and then post the message.

    The problem with this is that the user will have to click on the button more than once, not a big deal if it wasnt for the fact that when going back to the app, it is not remembering state, and opens the app from complete start, thus, user will have to take yet another picture, and click yet another time on the button, and login yet 2 more times, and loop, not posting the picture.

    Would be super if I could somehow test for permitions. Or figure out some other way to deal with all this.

    Advice is welcome.


    PS: prime31, I have used this for a while now, I know that I need to setup all those things. I am not saying its your fault or anything, I am saying that it is what happens. And instructions on possible issuies (FAQ) when updating versions would be a very good addition as I stated before.

    Here is my script : http://pastie.org/private/kc1bogc7elrtjond1ybhhq
    Appreciate if you guys could spot any problems and let me know.
     
    Last edited: Oct 1, 2012
  16. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @silent, I believe you can use the Graph API to see what permissions a user has provided. There is no avoid the new auth flow at this point as Facebook is deprecating the old way for iOS 6 Social and Accounts integration.
     
  17. SilentWarrior

    SilentWarrior

    Joined:
    Aug 3, 2010
    Posts:
    107
    Any idea why the app is getting reset when login in? Starts from scratch as if it was closed.
     
  18. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @silent, the Facebook SDK is responsible for session storage and retrieval so you will want to contact them.
     
  19. SilentWarrior

    SilentWarrior

    Joined:
    Aug 3, 2010
    Posts:
    107
    The Unity app gets reset, not the facebook app. Maybe I didnt make myself clear.

    It will request login, and when i click OK on the request, it goes back into the app and the app starts from scratch as if it was closed.

    I am guessing not everyone has this, or else everyone else would be here complaining since it makes it unusable. Also, I remember that in the old version, even if the app was closed, it would remember the session before : the "FacebookBinding.isSessionValid ()" would return true. This is no longer the case.
     
  20. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @silent, reduce your memory usage. iOS will always shut down your app if you are using too much memory and it is existed.
     
  21. trop

    trop

    Joined:
    Sep 5, 2012
    Posts:
    41
    hi prime!thanks for the reply, one more question, do you have any idea how fix images in unity, it seems that the images(profile pic and fb freindspic) are blurred when downloading using www/yield method.?
     
  22. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @trop, contact Facebook for any issues you have with the images. We have never had any issues with them personally.
     
  23. CPXTom

    CPXTom

    Joined:
    Apr 24, 2010
    Posts:
    113
    Hey, I'm using the latest version of the plugin. Is it possible to have the user login with-in the app, like in previous versions? Right now it's always opening in Safari (testing on a device running iOS5), we'd prefer to not leave the app to have the user log in.
     
  24. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @cpx, Facebook deprecated in app logins well over a year ago
     
  25. CPXTom

    CPXTom

    Joined:
    Apr 24, 2010
    Posts:
    113
    Hmm a few months or so ago I could still call authorizeWithFBAppAuth:NO safariAuth:NO and it would display a login dialog inside of the game. I'm guessing this is no longer possible? (looks like FBConnect 3.1 is pretty different!)
     
  26. SilentWarrior

    SilentWarrior

    Joined:
    Aug 3, 2010
    Posts:
    107
    Hello, I am trying to call "me/permissions" to check out if the app has permitions, but it crashes everytime with the message saying that it does not, even with a try catch block, ideas?

    Code (csharp):
    1.  
    2. void checkPermitions ()
    3.     {
    4.         if (hasPermitions) //dont wait
    5.             return;
    6.         try {
    7.             Facebook.instance.graphRequest ("me/permissions", HTTPVerb.GET, ( error, obj ) =>
    8.             {
    9.                 // if we have an error we dont proceed any further
    10.                 if (error != null || obj == null) {
    11.                     //print("error was: "+error);
    12.                     //not authorized application
    13.                     hasPermitions = false;
    14.                     relogin ();
    15.                     return;
    16.                 }
    17.                 hasPermitions = true;
    18.                 putMessage ();
    19.                
    20.                 // actually check for specific perms
    21.                 /*var ht = obj as Hashtable;
    22.             Hashtable perm = ((ht["data"] as Hashtable)[0] as Hashtable);
    23.             ResultLogger.logHashtable( ht );
    24.             if(!perm.ContainsKey("publish_actions"))
    25.                 relogin();*/
    26.             });
    27.         } catch {
    28.             hasPermitions = false;
    29.             relogin ();        
    30.         }
    31.     }
    32.  

    PS: all I want to do is post a simple message, but login has to work... complete code here : http://pastie.org/4898735
     
    Last edited: Oct 2, 2012
  27. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @silent, the following works fine for us:

    Code (csharp):
    1.             Facebook.instance.debugRequests = true;
    2.             Facebook.instance.graphRequest( "me/permissions", HTTPVerb.GET, ( error, obj ) =>
    3.             {
    4.                 Prime31.Utils.logObject( obj );
    5.             } );
     
  28. SilentWarrior

    SilentWarrior

    Joined:
    Aug 3, 2010
    Posts:
    107
    I have been stuck with this facebook thing for 2 days now.

    What I experience is the following :
    On facebook developer webpage, i have the app setup with Native login enabled, Deep linking disabled, and no URL scheme suffix.

    I wonder if you could provide me with a script that handles the login, permissions check and posting of a simple message all in one button (basically that works in a sequence). It is something extremely simple. I dont know what I am doing wrong, from what I read and see, everything should work just fine.

    Something that works even if :
    So basically.. a login and post message that just works, nothing too fancy.

    I have been trying to reach out to other ppl on irc, but so far no one else is replying, and since you guys built it, might aswell just ask you guys. And it would be of great use to other users too, since its not something specific.
     
    Last edited: Oct 3, 2012
  29. SilentWarrior

    SilentWarrior

    Joined:
    Aug 3, 2010
    Posts:
    107
    Hello. When loggin in, if facebook app from ios6 is installed, i get this message, when i click OK (for allow), nothing happens... basically stuck there.

    It reads : "AppName" Wants to access basic profile information and friends list, buttons are not allow and ok.
    https://dl.dropbox.com/u/1242729/fbMessage.jpg
     
  30. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @silent, open a bug report with Facebook. We have nothing to with that view. It is handled by Facebooks SDK.
     
  31. SilentWarrior

    SilentWarrior

    Joined:
    Aug 3, 2010
    Posts:
    107
    Is there a way to disable the "integration" stuff? For the normal post there is that variable we can test against, but, for login, is there anything? Force it to login using the standard webpage thing.

    Edit : In the mean time, here is a link to my bug report https://developers.facebook.com/bugs/385348808201568
     
    Last edited: Oct 3, 2012
  32. Kyhov

    Kyhov

    Joined:
    Sep 25, 2012
    Posts:
    8
    Hi prime31!

    i just bought social network! it was great for some methods, but i has problems, i can not get user name from facebook, just got account id. and by away i want get friends for invite my game! but the method Facebook.instance.getFriends(completionHandler); does't work! What should i do!

    thanks first for your answer!
     
    Last edited: Oct 3, 2012
  33. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @kyhov, Here is a link to Facebook's Graph API documentation. Read and understand it before trying to do anything with the Graph API. Many methods require additional permissions to be requested.
     
  34. Gaspedal

    Gaspedal

    Joined:
    Mar 29, 2009
    Posts:
    376
    I get the message: "[19989:707] no Facebook session available..." But my app is set-up correctly on facebook. I have sent request and that works fine, but I can't post message on may wall. Stay: no Facebook session available, why ?

    Login With:
    var permissions : String []= ["publish_actions","publish_stream"];
    FacebookBinding.loginWithRequestedPermissions( permissions );
    ....
    ......
    function Update(){

    if (FacebookBinding.isSessionValid()){
    if (!posted)
    Facebook.instance.postMessage ("POSTED!", null);
    posted = true;
    }
    }
     
  35. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @gaspedal, first off you are using an old version of the plugin. Publish permissions are no longer allowed by Facebooks SDK in the login method. They use a separate method for publish permissions now. I would recommend that you read our documentation and Facebooks documentation to learn how their new authentication system works.
     
    Last edited: Oct 3, 2012
  36. Gaspedal

    Gaspedal

    Joined:
    Mar 29, 2009
    Posts:
    376
    OK. In the past I have used the same way with my own plugins and that has works. :) I have bought your plugin yesterday (on AssterStore) :)
    Let's see what is new on Facebook. :)
     
    Last edited: Oct 3, 2012
  37. Gaspedal

    Gaspedal

    Joined:
    Mar 29, 2009
    Posts:
    376
    I have used the same permissions and on Facebook the names of the permissions are the same ? and still valid with login at same time?

    http://developers.facebook.com/docs/publishing/

    "There are two permissions,publish_actions and publish_stream, that allow you to publish stories or activity on behalf of the users of your app. If a user grants you a publishing permission, actions you take on the user’s behalf must be expected by the user and consistent with the user’s actions within your app.
    If your app requires any publishing abilities not listed above, then you will need to request the publish_stream permission."


    I have started my App and this asked my for permission and I have confirmed with yes.
     
    Last edited: Oct 4, 2012
  38. Gaspedal

    Gaspedal

    Joined:
    Mar 29, 2009
    Posts:
    376
    Ahhh, now it works! I have logged out, deleted my App, and created a new build. After installing now it works :)
     
  39. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    I'm having a very strange problem. If Facebook users give permission to my app to post on their half on the first visit to the initial scene, it works. But when I go back to that scene after having played the game, all my CoRoutines get NullReferenceExceptions when called from code that gets fired from a delegate of "FacebookManager.loginSucceededEvent".

    That looks like this:
    ------------
    error calling coroutines: System.NullReferenceException:
    at UnityEngine.MonoBehaviour.StartCoroutine (IEnumerator routine) [0x00000] in <filename unknown>:0
    at FacebookLogin.GetFriendScoresAndAccessToken () [0x00000] in <filename unknown>:0
    UnityEngine.Debug:Internal_Log(Int32, String, Object)
    UnityEngine.Debug:Log(Object)
    ------------

    The 2nd time it happened, I got this message:

    "Coroutine couldn't be started because the the game object 'P31CoroutineSurrogate' is inactive!"

    How to troubleshoot this strange problem?
     
  40. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jerotas, it sounds like you are calling a method possibly between scene loads when all objects are sent OnDisable. You should make yourself a Queue and only send after the new scene is fully loaded and OnEnable has been sent to all objects.
     
  41. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    That sounds good. Is there any easy way to know when the scene if fully loaded?
     
  42. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jerotas, just see if the P31CoroutineSurrogate.enabled is true.
     
  43. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    Right on, I checked Application.isLevelLoading for false :) Thank you!
     
  44. Kyhov

    Kyhov

    Joined:
    Sep 25, 2012
    Posts:
    8
    Hi prime31!

    how can i create own methods to do anythings in my game for community with facebook grap like view friends list or anythings that i want!

    thanks first!
     
  45. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
  46. DoktorAce

    DoktorAce

    Joined:
    Jul 13, 2012
    Posts:
    12
    Hi,

    Question #1: Our game wants to request some publish permissions when the player clicks the "Social Connect" button. However, SocialNetworking doesn't let us request publish permissions when logging in. Clearly, requesting read permissions first, then reauthorizing and asking for publish permissions is unacceptable. We noticed there is an API function in the Facebook SDK that does allow you to request publish permissions when starting a session, but it is not exposed by the Prime31 plugin. What is the intended flow here?


    Question #2: The plugin forces us to request the "email" permission when logging in. We do not need or want this permission and feel that including it increases friction. Is there any reason why this is required? Our experiments indicate there is no real reason to force us to request this permission and simply hacking it out of the plugin didn't seem to make a difference (other than not requesting it). To maintain compatibility with future updates we'd really like to avoid having to do this.


    Question #3: This is the big one for us. The new version of the plugin supports posting highscores to Facebook, but doing this just results in the Facebook SDK complaining that we need an app access token, then it crashes. However, Facebook does not allow you to use app access tokens in mobile applications as this is a security risk. How is this supposed to function? The player has already granted the "publish_actions" permission, but it changes nothing.


    This might be posted again, since I first tried to post them through a different account. Sorry about that.
     
  47. jeroenx000

    jeroenx000

    Joined:
    Oct 4, 2012
    Posts:
    27
    Hello,

    How can I create a pop-up facebook log in?

    is it loginWithRequestedReadPermissions?

    Thank.
     
  48. Gaspedal

    Gaspedal

    Joined:
    Mar 29, 2009
    Posts:
    376
    @prime: On iPad 2 3 with iOS 5.1 works fine with login and posting messages. But on iPhone4S (iOS5.1) the game crashes with sigbus error. XCode says:

    libsystem_kernel.dylib`__pthread_kill:
    0x360db324: mov r12, #328
    0x360db328: svc #128
    0x360db32c: blo 0x360db344 ; __pthread_kill + 32
    0x360db330: ldr r12, [pc, #4] ; __pthread_kill + 24
    0x360db334: ldr r12, [pc, r12]
    0x360db338: b 0x360db340 ; __pthread_kill + 28
    0x360db33c: ldmibeqr3, {r5, r6, r7, r10, r11, r12, lr, pc} ^
    0x360db340: bx r12
    0x360db344: bx lr

    com.facebook.sdk:InvalidOperationException', reason: 'FBSession: No AppID provided; either pass an AppID to init, or add a string valued key with the appropriate id named FacebookAppID to the bundle *.plist'
    *** First throw call stack:
    (0x3582588f 0x37bcc259 0x358255c5 0x1021694 0x10214d0 0x1022b34 0xa49aec 0xa48b5c 0x1381c4 0xf5a48 0x1b8504 0x1b7390 0xc1f608 0xc1df3c 0xbafb0c 0xbafb64 0xbfd528 0xa71a40 0xec410 0xec378 0x326a386f 0x326a37c5 0x32a01001 0x3431b60d 0x357eef13 0x357f9523 0x357f94c5 0x357f8313 0x3577b4a5 0x3577b36d 0x37417439 0x33287cd5 0xedb9c 0xea7b8)
    terminate called throwing an exception


    what is the problem ? I use the latest plugin and on iPads it works fine. Why it doesn't work on iPhone 4S ?
     
    Last edited: Oct 4, 2012
  49. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @doktor, 1. Facebook deprecated the old login system in favor of the new one that only allows read permissions for login. 2. Facebook's documentation requires that you have one of the three permissions listed in their docs. We chose email since it is the most common. 3. Facebook recommends that you do not use app access tokens but there is nothing stopping you from using them. To increase security do the calls from your own server.


    @jeroenx, Facebook deprecated in app logins well over a year ago.


    @gaspedal, everything works fine on the iPhone 4S for us. The error seems to indicated that you did not provide a valid appId. If it works on all other devices perhaps try restarting your device.
     
  50. Gaspedal

    Gaspedal

    Joined:
    Mar 29, 2009
    Posts:
    376
    Appid is valid because it works fine on iPad23. I have rebootet my phone but I get the same error and the app crashes. I will later try to rebuilding the project. I'm now out of home. :)