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

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

  1. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @Jtown, I just pushed an update with the following change: added automatic conversion of Unicode characters for all Graph API methods
  2. JTown.

    JTown.

    Member

    Joined:
    Jan 9, 2010
    Messages:
    858
    Sweet thanks. Works perfectly.
    Last edited: Apr 29, 2012
  3. swiv

    swiv

    New Member

    Joined:
    Mar 22, 2009
    Messages:
    30
    Has anybody else noticed that in ios 5.1, if you log in to Facebook then immediately call showPostMessageDialog the dialogue box immediately closes? If you call showPostMessageDialog a second time it works and you can post.

    This only happens in ios 5.1, ios 5.0 and lower it's fine. Would like to know if anybody else can reproduce this behaviour.
  4. toshiya

    toshiya

    New Member

    Joined:
    Apr 27, 2012
    Messages:
    8
    Hi Prime.
    After revising your answer for the cause, I moved normally. Thank you!
  5. yuriythebest

    yuriythebest

    Member

    Joined:
    Nov 21, 2009
    Messages:
    944
    Hi prime! making progress with the twitter binding, however when I attempt the following:

    (with the aim of getting output like)

    Code (csharp):
    1. void twitterHomeTimelineReceived( ArrayList result )
    2.     {
    3.         string resultText="";
    4.  
    5.         for(int i=0;i<6;i++)
    6.         {
    7.             Hashtable twitterData=(Hashtable) result[i];
    8.             string newString= twitterData["screen_name"].ToString()+": "+ twitterData["text"].ToString();
    9. .
    10. .
    11. .
    12.  

    I get results like:
    meaning the "screen_name" is null for some reason while "text" works- how do I fix this?


    EDIT:
    Okay here is an extract from the logger you recommended:
    Code (csharp):
    1.  
    2. n_reply_to_user_id_str:
    3. in_reply_to_status_id:
    4. text: Ghj
    5. created_at: Tue May 01 13:54:13 +0000 2012
    6. in_reply_to_status_id_str:
    7. source:  /////////redacted
    8. in_reply_to_user_id:
    9. retweet_count: 0
    10. contributors:
    11. in_reply_to_screen_name:
    12. user: profile_image_url_https: https://si0.twimg.com/profile_images/490147714/matrix_normal.jpg
    13. show_all_inline_media: False
    14. contributors_enabled: False
    15. lang: en
    16. profile_use_background_image: True
    17. profile_sidebar_border_color: C0DEED
    18. profile_background_image_url_https: https://si0.twimg.com/images/themes/theme1/bg.png
    19. default_profile_image: False
    20. geo_enabled: False
    21. following: False
    22. name: yuriy nikshych
    23. profile_image_url: http://a0.twimg.com/profile_images/490147714/matrix_normal.jpg
    24. profile_link_color: 0084B4
    25. profile_text_color: 333333
    26. utc_offset:
    27. created_at: Wed Feb 04 19:02:44 +0000 2009
    28. protected: False
    29. follow_request_sent: False
    30. id_str: 20080308
    31. favourites_count: 0
    32. notifications: False
    33. profile_background_color: C0DEED
    34. profile_background_tile: False
    35. id: 20080308
    36. listed_count: 0
    37. friends_count: 7
    38. is_translator: False
    39. default_profile: True
    40. profile_sidebar_fill_color: DDEEF6
    41. screen_name: yuriythebest
    42. profile_background_image_url: http://a0.twimg.com/images/themes/theme1/bg.png
    43. followers_count: 15
    44. time_zone:
    45. verified: False
    46. url:
    I've tried both "name" and "scene_name" but they seem to be null in Unity, while the logger says they have values

    I've even tried

    Code (csharp):
    1. if(twitterData["name"]!=null)
    2.                 newString+=twitterData["name"].ToString()+": ";
    3.              newString+=  twitterData["text"].ToString();
    but that leads to the same result as before
  6. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
  7. yuriythebest

    yuriythebest

    Member

    Joined:
    Nov 21, 2009
    Messages:
    944
    indeed good sir that was the case, many thanks!
  8. shadowfork

    shadowfork

    Member

    Joined:
    Jan 8, 2010
    Messages:
    153
    For Facebook...

    Is 'isSessionValid()' same as 'isLoggedIn()' ?
    I know the latter was dropped, but is it okay to use the session in replacement of this?

    Also, I just caught isSessionValide turn to TRUE even though I wasn't able to login properly. Investigating this one.
  9. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @shadow, isSessionValid will return true as long as there is a valid access token present that has not expired.
  10. CHICAN0

    CHICAN0

    New Member

    Joined:
    May 5, 2011
    Messages:
    4

    Can you tellme exactly whats the example or code line to get MY id into a variable please... Thanks.
  11. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @chicano, the example does exactly what you are looking for. It grabs the user id and stores it in an instance variable.
  12. Kuroe

    Kuroe

    New Member

    Joined:
    May 4, 2012
    Messages:
    2
    Hey there,

    I've been trying to post a tweet, but when I do so I get :

    SendMessage: object TwitterManager not found!

    The tweets are posted, but I can't notify the user as Action twitterPost is not triggered.

    How can I solve that please ?
  13. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @kuroe, it looks like you do not have the TwitterManager prefab in your initial loading scene. Add it and the error will be resolved.
  14. Kuroe

    Kuroe

    New Member

    Joined:
    May 4, 2012
    Messages:
    2
    @Prime31, thanks, that did the trick ! Surprisingly the FacebookManager is working perfectly without having a prefab instance in the scene.
  15. olramarlo

    olramarlo

    New Member

    Joined:
    May 9, 2012
    Messages:
    2
    Hi Prime31,

    Any idea on how to fix " Unknown identifier: 'HTTPVerb'."?

    I'm coding in UnityScript and here's a snippet of my code:

    Code (csharp):
    1. var postParam : Dictionary.<String, Object> = new Dictionary.<String, Object>();
    2. postParam.Add("message", "Test Message");
    3. postParam.Add("link", "http://www.google.com");
    4. postParam.Add("name", "Link Name");
    5. postParam.Add("caption", "Post Caption");
    6. postParam.Add("description", "A very long description");
    7.        
    8. Facebook.instance.graphRequest("123456789/feed", HTTPVerb.POST, postParam, PostedToFriendsWall);
  16. olramarlo

    olramarlo

    New Member

    Joined:
    May 9, 2012
    Messages:
    2
    oh nevermind, Got it working, just added

    Code (csharp):
    1. import Prime31;
    on top of script.
  17. EricD

    EricD

    New Member

    Joined:
    Sep 7, 2011
    Messages:
    128
    How big can a screenshot be when I upload it to facebook? Cause If we try to upload a screenshot it doesn't work. It just doesn't get uploaded. But if we upload a really low res image it works.
  18. Katia

    Katia

    New Member

    Joined:
    Aug 5, 2011
    Messages:
    9
    I am having some problems integrating Facebook into my game. I did managed to post to the wall before . However today I am getting this error from the Xcode:

    ghashtable.c:294: assertion 'hash != NULL' failed,

    It does one of the following every time i try to post : it asks for permissions and redirects me back or redirects me to Facebook or doesn't even ask for permissions and redirects right back. The Problem is that it keeps asking for permission(or just redirecting and going back) even when it supposedly got it . So i never get to actually posting.

    I just noticed this behavior today, when i initially put in the code it seemed to work fine. I did not change the code...

    any ideas what could be causing it?

    my code:


    public void FacebookButtonPressed1()
    {
    //Initialize
    FacebookBinding.init( "*********" );
    //Login Try
    bool isLoggedIn = FacebookBinding.isSessionValid();
    if (!isLoggedIn)
    {
    var permissions = new string[] { "publish_actions", "user_games_activity" };
    FacebookBinding.loginWithRequestedPermissions( permissions );
    }
    else
    {

    Facebook.instance.postMessage( "1234", completionHandler );
    }
    }
  19. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @eric, you will need to check Facebooks docs for the image size constraints.


    @katawa, have you tried deleting your app an reinstalling? That often clears up odd issues like this whn testing.
  20. Katia

    Katia

    New Member

    Joined:
    Aug 5, 2011
    Messages:
    9
    Yes, I deleted it and reinstalled it several times. No luck...

    Perhaps it is somehow connected to the app settings in Facebook. I noticed that if the app is set to native iOS then i do not at all get to the "permission asking" state, it's just redirects to Facebook and then redirects back (no posting).

    If it set to a web app then i get to see the permissions window, i get to allow it but that is all. The second time it takes me to the permissions again,never get to actually posting to a wall.

    It didn't happen few days ago , when i initially integrated the plugin. Perhaps it is something else in the Facebook app settings i changed unintentionally...

    I will really appreciate any help on fixing this issue.

    Thanks,
  21. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @katuwa, your app should absolutely be setup as a native iOS app and you must put your bundle ID in there as well. Those are required for Facebooks SDK to be able to authenticate a user.
  22. Katia

    Katia

    New Member

    Joined:
    Aug 5, 2011
    Messages:
    9
    ok, thanks, but then it comes back to the:

    ghashtable.c:294: assertion 'hash != NULL' failed, : Error i get

    in this case i do not even get to the "ask for permission state"....
    what else can i be doing wrong?
  23. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @katuwa, have you tried the demo scene? It is a working example of all the available calls the plugin offers and is an excellent place to start.
  24. EricD

    EricD

    New Member

    Joined:
    Sep 7, 2011
    Messages:
    128
    But a normal retina screenshot should work right?
  25. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @eric, it *should* work and my tests appear to work fine.
  26. Katia

    Katia

    New Member

    Joined:
    Aug 5, 2011
    Messages:
    9
    Prime31 thank for your reply, I just made a build of your demo scenes and it kind of gives me the same problem.

    Once the app is set to native iOS, the errors :

    ghashtable.c:294: assertion 'hash != NULL' failed
    ghashtable.c:294: assertion 'hash != NULL' failed
    ghashtable.c:294: assertion 'hash != NULL' failed
    ghashtable.c:294: assertion 'hash != NULL' failed
    ghashtable.c:294: assertion 'hash != NULL' failed....

    So i guess the problem is in the way i set my app on Facebook.
    My app was not published yet, so Facebook doesn't allow me to insert the apple id of an app that wasn't published yet.
    I set it app with the correct bundle id but with a different app store id.

    Could that be the issue?

    if so, how else can I test it?
  27. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @katauwa, the errors you are getting dont seem to be coming from any files within the plugin of within Facebook's SDK. I believe you may have something else going on. For the app ID, I usually just enter the app ID from any app live in the App Store to get a valid one.
  28. byerdelen

    byerdelen

    Member

    Joined:
    Mar 27, 2010
    Messages:
    40
    Hi Prime,
    I have faced a weird problem on plugin. I have sent a dialog and things are fine, when I press Send, it sends and the facebokDialogCompleted is fired and when i press the cross on top, it fires up facebokDialogdidntCompleted. The problem is when I press cancel button instead of send, it fires up facebokDialogCompleted also. To explain better, there are 3 buttons as you know, one is the top right cross to close the dialog and two buttons on left to cancel and on right to send. Even if I press the cancel, on the left, I fires up the event facebokDialogCompleted and not the others as facebookDialogFailed or facebokDialogdidntCompleted.
    I am opening up some bonus in case they send it so I need to know they pressed the send button. Am I doing something wrong? OR is there another event fired with the send button for Facebook dialog?
    Thanks
  29. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @beyer, if you are looking to reward users a better option would be to listen to the dialogCompletedWithUrlEvent which returns actual request IDs and other information from the dialog.
  30. StevenVerbeek

    StevenVerbeek

    New Member

    Joined:
    Aug 12, 2011
    Messages:
    13
    I'm facing an issue with the postscore method in your plugin.
    Any advice on this?


    Unloading 3 Unused Serialized files (Serialized files now loaded: 0 / Dirty serialized files: 0)
    First call the 'me' graph request to gather the user's userId

    (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 34)

    you must first retrieve the app access token before posting a score

    (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 34)

    score post suceeded? False

    (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 34)

    app access token retrieved: 208082439215773|H1nF4smKMf_w-8VFxIQYB-j7ItI

    (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 34)

    InvalidCastException: Cannot cast from source type to destination type.
    at Facebook+<postScore>c__AnonStorey1.<>m__2 (System.String error, System.Object obj) [0x00000] in <filename unknown>:0
    at Prime31.P31RestKit.processResponse (UnityEngine.WWW www, System.Action`2 onComplete) [0x00000] in <filename unknown>:0
    at Prime31.P31RestKit+<send>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0

    (Filename: Line: -1)
  31. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @steven, it looks to me like you didn't fetch the app access token before calling postScore.
  32. StevenVerbeek

    StevenVerbeek

    New Member

    Joined:
    Aug 12, 2011
    Messages:
    13
    I forgot to switch the category to Games, fixed my issue.
  33. jnakai

    jnakai

    New Member

    Joined:
    Aug 28, 2009
    Messages:
    38
    How does the plugin handle multiple accounts registered with tweet sheet? Is there a way we can let the user choose the account to send the tweet through or does it simple revert to the first account?
  34. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @jnakai, the Tweet Sheet is entirely handled by Apple. You don't get to choose anything when using it.
  35. jnakai

    jnakai

    New Member

    Joined:
    Aug 28, 2009
    Messages:
    38
  36. andrey_bryzgalov

    andrey_bryzgalov

    New Member

    Joined:
    May 15, 2012
    Messages:
    2
    I am considering to purchase social plugins for iOS and Android.
    Does it support facebook deep-linking?
    I have found no event like "applicationDidOpenWithURL" in bindings.
    Are there plans to add it in nearest future?
    Or maybe I can extend plugins to support it? Is it possible?
  37. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @andrey, deep linking is not supported and as of now we have no plans to add it.
  38. StevenVerbeek

    StevenVerbeek

    New Member

    Joined:
    Aug 12, 2011
    Messages:
    13
    any advice on how I could manage a weekly high score contest?

    Now I come to a point where I need the weekly high score and the all time high score.
    bejeweled blitz and diamond dash have this.

    It looks like I'm only able to receive 1 score per user per game. Am I missing a method to request all scores with dates?
  39. Iamdain

    Iamdain

    Member

    Joined:
    Feb 3, 2010
    Messages:
    61
    Hi Mark,

    I've successfully logged into twitter with oAuth and can post text messages. When posting with an image however using:

    Code (csharp):
    1. string path = Application.persistentDataPath + "/ScreenShot.png";
    2. TwitterBinding.postStatusUpdate( "I'm posting this from KnockedApp with an image: " + Time.deltaTime, path);
    The debugger tells me 'Successfully posted to Twitter', yet no post appears in my Twitter feed.

    I'm sure the path is correct as I'm able to store from this path to the picture library using your saveImageToPhotoAlbum function.

    Any ideas as to what might be the problem?

    Cheers,
    O
  40. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @oddap, is the twitterPost or twitterPostFailed event firing?
  41. Iamdain

    Iamdain

    Member

    Joined:
    Feb 3, 2010
    Messages:
    61
    Hi, twitterPost fires
  42. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @oddap141, if twitterPost is firing then Twitter is returning a success packet. You may need to shoot a bug request over to the Twitter crew to get to the bottom of the issue.
  43. DCalabrese

    DCalabrese

    Member

    Joined:
    Dec 13, 2011
    Messages:
    227
    I upgraded to the latest version of the SocialNetworking plugin, and I'm afraid that Facebook is no longer working for me. In the debug log in Xcode, I can see that after the user has logged in to Facebook and the application returns from the Facebook page, I see this in the console:

    SendMessage: object FacebookManager not found!

    It looks like FacebookManager is part of the component that is on the SocialNetworkingPrefab object, which I do indeed have in the scene.

    After the login, whenever I try and allow the user to post to their wall, I get this error:

    error: message: An active access token must be used to query information about the current user.
    type: OAuthException
    code: 2500

    Which I'm guessing is related to the previous error of not being able to find FacebookManager.

    Any hints on how to fix this?
  44. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @D, the latest version of the plugin had major API changes so be sure to delete the old files. The error is indicating that you don't have a FacebookManager prefab in your scene which means native code cannot communicate with Unity.
  45. DCalabrese

    DCalabrese

    Member

    Joined:
    Dec 13, 2011
    Messages:
    227
    Ahhh okay. I don't even have a FacebookManager prefab in my project, so I'm thinking there was some file overlap / import failure. Going to wipe the import and re-import fresh. Thanks!
  46. DCalabrese

    DCalabrese

    Member

    Joined:
    Dec 13, 2011
    Messages:
    227
    Ok, so clearing and re-importing did indeed fix the login error. The login now completes successfully. However, I still get this error whenever posting to the Facebook wall:

    error: message: An active access token must be used to query information about the current user.
    type: OAuthException
    code: 2500

    Mind you, this is still the same code and setup that did work before. What else might have changed that would prevent an access token from getting made, when it did get made before?
  47. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @D, the reasons for login not occurring successfully are almost always not setting up your bundle ID properly or not setting up your URL scheme properly. Double and triple check them.
  48. DCalabrese

    DCalabrese

    Member

    Joined:
    Dec 13, 2011
    Messages:
    227
    Got it. The reason was that I was trying to post too soon after logging in, so the access token had not yet been stored. If I wait a moment then post, it goes through fine.

    1 more question from here... Is there any way using the Facebook.instance.postImage command to display a popup of some kind of what is being posted for the user to confirm?
  49. prime31

    prime31

    Member

    Joined:
    Oct 9, 2008
    Messages:
    6,424
    @D, everything in the Facebook class is a Graph API call so there is never any UI associated with it. The Graph API is 100% data only calls.
  50. DCalabrese

    DCalabrese

    Member

    Joined:
    Dec 13, 2011
    Messages:
    227
    Very cool, makes sense. So if I wanted to show one of the existing Facebook dialogs, I would need to use the specialized Graph API calls that I can call through the Facebook class. Or just use an in-app custom dialog (which is what I think I may just do in this case).

    Thank you very much for all your help! I think I owe you a free copy of this game. :)