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

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

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

  1. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Jay, whether you use Xauth or Oauth the plugin will absolutely never store a users credentials. It will only store the access tokens. Once a user is logged in its simply a call to postStatusUpdate to post to Twitter.
     
  2. Dev.D1

    Dev.D1

    Joined:
    Dec 29, 2010
    Posts:
    99
    @Prime31 - Thanks for the plugin. We're using the Facebook authorization without issues. Haven't tried Twitter yet .Our app is just using the Facebook/ Twitter for user authentication. We'd like to add Google account authentication as well.

    Questions:
    1) I was wondering if you had any plans for supporting Google Authentication and Authorization API .

    Specifically , OAuth 1.0 for Installed Applications and / or OpenID.


    2) Any plans for supporting Google Plus when the API goes public. I know its a bit hypothetical right now but would you add support for this in the social networking plugin or would that be a separate thing we'll have to purchase?
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Dev.D, I'm not sure what exactly you are looking for with regard to Google's OAuth. They have dozens of services that use it...as for Google+, well, first we need and API then it needs to last longer than Google Wave did and we can talk about it then.
     
  4. dokosten

    dokosten

    Joined:
    Jun 9, 2009
    Posts:
    16
    Hi there, Prime31. We love your plugins, so keep'em comming please. =)

    However, we have a problem with the showPostMessageDialog methods, the message text does not appear! This worked in the live version of our app before, but it has suddenly stopped working without us doing anything on our side. This is most likely a problem on facebook's side, but I thought I'd ask you about this anyways as it's not been working for at least 3 days, probably longer.

    So, you got any clue what causes this? We've tried building with Unity3D 3.3 and 3.4, no luck with any of them.


    Cheers.
    -DoKosten
     
  5. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @dokosten, you need to read your emails :) We pushed out an update a few days ago with a message about this. Facebook has removed the ability to prefill a message with some mumbo jumbo claim of some sort. We removed the message parameter but felt bad taking stuff away so we added full REST support.
     
  6. dokosten

    dokosten

    Joined:
    Jun 9, 2009
    Posts:
    16
    Oh, damn facebook :(

    Anyways, we are not receiving any mails from you about updates on your plugins. I've mailed you guys about it, so please make sure we still are on your mailing list. =)

    Cheers!
     
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @dokosten, I believe I already responded to your email.
     
  8. schwertfisch

    schwertfisch

    Joined:
    Sep 7, 2010
    Posts:
    126
    Hello Prime31 and fellow SocialNetworkingPlugin users,

    the facebook part works just fine for me, but I'm having a big trouble making twitter to work.
    (please note I currently only use JavaScript)

    1) I went to https://dev.twitter.com/apps
    2) I chose "Create a new application"
    3) In the "application details" page, I input a name and description. On the "website" field I input the iTunes link. I used this link for the "Callback URL" too, as from what I've read it doesn't matter what I put there.
    4) I dropped a SocialNetworkingManager prefab in my game's 1st scene. In the basic script that controls scene 1, under function Awake I have put the line:

    Code (csharp):
    1. TwitterBinding.init("my Consumer key here","my Consumer secret here");
    5) When the player finishes level 1 (scene 2 for Unity), they are presented with a panel telling them how fast they were and 2 buttons, one for facebook and another for twitter posting. As I said, the fb button works fine. The twitter button calls the following function:

    Code (csharp):
    1. function TwitterPost (){
    2. if (TwitterBinding.isLoggedIn()){
    3.     TwitterBinding.postStatusUpdate("I'm playing the arithmetic iphone app ''d'Aritmetique''!");
    4.     }
    5. else if (!(TwitterBinding.isLoggedIn())){
    6.         TwitterBinding.showOauthLoginDialog();
    7.         }
    8. }
    Pressing the button doesn't do anything.

    What am I doing wrong?
    Also what exaclty does this mean: "make sure you setup your app on the Twitter website as a Browser app"?

    Thanks :)
     
    Last edited: Aug 9, 2011
  9. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @schwert, do you see any info in the Xcode logs? Have you wired up event listeners (or just included the prefab)? Adding a callback URL is essentially turning your Twitter app into a browser app so you are all set there.
     
  10. schwertfisch

    schwertfisch

    Joined:
    Sep 7, 2010
    Posts:
    126
    That was it prime, thanks so much for the instant reply!
    I'm sorry for being such a noob, but I'm into Unity programming (JS only) for just 10 months.

    So I have to drop the SocialNetworkingEventListener prefab to every scene in the game? (the facebook and twitter post buttons appear at the end of each level, before proceeding to the next one).
     
  11. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @schwert, the EventListener prefab is only required for debugging and for reference. It will print important info to the Xcode log.
     
  12. schwertfisch

    schwertfisch

    Joined:
    Sep 7, 2010
    Posts:
    126
    After I dropped the SocialNetworkingEventListener prefab in my scene, the Twitter post was published for the 1st time. The problem must have been something else that I'm missing then. Anyway, thanks a bunch prime ;-)
     
  13. mtewks

    mtewks

    Joined:
    Jun 10, 2011
    Posts:
    82
    I was looking through the docs, doesn't seem to be a way to invite friends who have the app to join a game.
    I've been looking in the API Graph too, but I'm not getting very far. Anyway to do that?
     
  14. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @mtewks, you will have to dig through the REST and Graph API docs to find the answer (or post on their developer forums).
     
  15. mtewks

    mtewks

    Joined:
    Jun 10, 2011
    Posts:
    82
    For the following function;
    public static void graphRequest( string graphPath, string httpMethod, Hashtable keyValueHash )

    How does one find the graph path?
    What is the httpMethod?
    Is the hashtable what's going to hold all of the players data?
     
  16. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @mtweks, the graphPath is directly out of the Facebook Graph API documentation as is the HTTP method. The Hashtable's contents is 100% dependent again on the Graph API docs for what you are trying to do. Every Graph API method has a list of parameters, the required HTTP method and the path.
     
  17. hencz

    hencz

    Joined:
    Aug 19, 2010
    Posts:
    86
    Hi Prime31,
    Any way to access the description parameter in showPostMessageDialogWithOptions?
     
    Last edited: Aug 11, 2011
  18. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @hencz, that info gets pulled from the meta tags on the website.
     
  19. hencz

    hencz

    Joined:
    Aug 19, 2010
    Posts:
    86
  20. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @hencz, good find. I'll expose a version that takes a Dictionary<string,string> for maximum flexibility in the next update.
     
  21. mtewks

    mtewks

    Joined:
    Jun 10, 2011
    Posts:
    82
    Does the GraphRequest assume you've already logged in?

    Currently trying to figure out how to log in as a test user. From there I'll be trying to use the
    Graph Request to access his data.
     
  22. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @mtewks, you must have a valid access token to use Graph API requests.
     
  23. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @hencz, I just added the new method. Grab the latest package to get it.
     
  24. hencz

    hencz

    Joined:
    Aug 19, 2010
    Posts:
    86
    cool, thanks :D
     
  25. mtewks

    mtewks

    Joined:
    Jun 10, 2011
    Posts:
    82
    Hmm, unsure how to use graphRequest still. Wish I could figure out how to use the test users too.

    Something that is confusing me, however is the getLoggedinUsersName() and getFriends(). Seeing as how they return void
    I don't see how I can make use of them. I did try to use the getFriends() in hopes of a Facebook friends box popping up, but nothing happened.
    Or does that function only work if there are friends with the app installed?
     
  26. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @mtewks, all the requests return void because they are just sending off requests over the network. You need to listen to the relevant events that get fired when the network request is finished. We have a video tutorial in the docs on events if you aren't familiar with them and there is prefab with an example of listening to every event the plugin has.
     
  27. mtewks

    mtewks

    Joined:
    Jun 10, 2011
    Posts:
    82
    You mean the SocialNetworkingEventListener?
    Wish I knew that was there sooner. XP
     
  28. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @mtewks, the demo scenes always show how to do just about everything the plugin offers. Be sure to play around with them to see what is possible and how to do it.
     
  29. mtewks

    mtewks

    Joined:
    Jun 10, 2011
    Posts:
    82
    I tried one of the demo scenes, however I kept getting error, failed to get users name when pressed the Get User's Name button.
    I did remember to put the App ID in so not sure what went wrong.

    I was also getting a message from FB that an error accord when it popped up.
    Either something is wrong with FB or something with the code. Hard to say atm.
     
    Last edited: Aug 12, 2011
  30. byerdelen

    byerdelen

    Joined:
    Mar 27, 2010
    Posts:
    68
    Hi Prime31,
    I know you are tired of that kind of requests but can you please just write me a good working twitter and facebook code?
    In twitter I initialise in Start, then I make the login oauth and the user logins and accepts the permission, i have never made the login bool working so after that, the twitter pops up again and i need to login auth because user has to accept the permission again (it worked for me only like that) and after that the twitter has to pop up again to post the message this time. Thats all, I need the working code to login and post the message. I am not good at C++ coroutines to try that again and again.
    And for facebook the same login thing and the custom feed dialog to make those coroutines.
    And if anyone has that codes working, please lat me know the code, they are simple but I am tired to try all the ways.
    Thanks Prime31 and the community!
     
  31. Initial

    Initial

    Joined:
    Aug 13, 2011
    Posts:
    1
    Hey guys I have a dilemma, not sure if anyone else has tried this yet but ...

    I log the user in using loginWithRequestedPermissions() if they are not already logged in and then allow them to post. So that is working okie dokie, but when I go into facebook, go into Account Settings -> Application and remove my app, the facebook binding still thinks I'm logged in, and then attempts to post but in the end it does not post to facebook. Is there some way to know if I still have the users permission or able to ask the user to give permission again?

    [EDIT] at one point I also put in getFacebookAccessToken() != null
     
    Last edited: Aug 17, 2011
  32. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Initial, why not just listen to the failed event for the post and relogin if necessary?
     
  33. byerdelen

    byerdelen

    Joined:
    Mar 27, 2010
    Posts:
    68
    Hey Prime31,

    I still have troubles in Facebook side and couldnt solve it.
    I am only using the FacebookBinding.showPostMessageDialogWithOptions method and it is working very well if I am logged in.
    But if I am not logged in, it opens the login page and make me login so thats perfect, only it directs me to the app back instead posting the message. So I need to click it again. How can I make it working directly after? I tried after succesful login post the message but it didnt work. I have no problem on initialise because in case of logged in, no problem. And also I do not want the login process because it needs person to allowance since the postmessage method does not need it
    Can you shoot me that piece of code that is working it correctly that with one click it opens the login screen and after automatically the post message screen?

    Thanks alot
     
  34. byerdelen

    byerdelen

    Joined:
    Mar 27, 2010
    Posts:
    68
    Also my Twitter Xauth request is turned down that they said they are not giving permanent access to any library anymore because they do not have any reporting mechanisms. Although I just told I will setup everything myself. So I will go with the Oauth
     
  35. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @byerdelen, you have to authenticate the user before showing the post message dialog. That code all runs on Facebook's servers and you have no control over it so if you login properly first you won't have the issue.

    After login when you posted the message did you get the dialogDidSucceedEvent? If not, did you get the dialogDidFailEvent and what was the error message? There may also be some info in the log cat logs as well.
     
  36. byerdelen

    byerdelen

    Joined:
    Mar 27, 2010
    Posts:
    68
    So that is the main idea I am using to test. It is working if it is online.
    If it is already logged in, it works very well.
    But I want to make things automatic when it is logged of. Like the player just click a button and it goes directly to the loging and when it coms back to the app after successful login, it automatically pops up the custom feed dialog. In this code, it is not doing, I have to press it again. What am I doing wrong. Sorry to disturb you Prime, I am newbie coder of JS, no knowledge of C# and couldnt just understand it from the examples what i wanted to do
     
  37. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    Just check to see if the user is logged in and if they are show the dialog. If they are not, log them in then show the dialog. Be sure to listen to the appropriate events (see the *EventListener script for examples if you don't know how to use events).
     
  38. byerdelen

    byerdelen

    Joined:
    Mar 27, 2010
    Posts:
    68
    I spent some hours and ported all necessary codes to JS. Now that awesome beast works like a charm as soon as I know how to use the language properly.
    Thank you Prime31 for your help and sorry to bother you.
     
  39. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    This plugin works only with IOS or can it be used on a Pc/Mac game ?
     
  40. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @BigB, plugins are just like apps. They are written in code native to the platform so you cannot run a plugin on any platform besides the one it is written for. It would be like trying to run an iOS app on your Windows computer.
     
  41. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Hi, Prime,

    I am sorry to bother you, but I have big troubles with the Facebook plugin. (Twitter will be next trouble... I guess, but I don't have time to test it yet.)

    When I Call "FacebookBinding.login()", my app quit (UIApplicationExitsOnSuspend is checked), Facebook app pop up, it ask me for the permission, I tap permit.

    After that, when I call "FacebookBinding.isLoggedIn()", it always returns false.

    I just know the Facebook app pop up is normally, but how can I get the logged in state when my app quit and run again? (I don't want my app keep running in when it is in the Task bar.)

    BTW, when should I use the function "getFacebookAccessToken()" ?

    I am sorry maybe these are very stupid questions.
     
    Last edited: Aug 29, 2011
  42. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @donlien, did you follow the instructions in the documentation with regard to setting up a URL scheme? If you dont set it up correctly then you will never get an access token and hence never be logged in. With regard to getFacebookAccessToken, if you have to ask what it is for then you don't need it. It is for advanced Facebook developers.
     
  43. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    @Prime31 Yes, I've typed "fbxxxxxxxxx" things in that dialog.

    I don't know what happened just now.

    I tried to set "UIApplicationExitsOnSuspend" to unchecked, log in by FB app, isLoggedIn() return true finally.

    Facebook told me my picture was not able to use in stream mode, so I removed the "picture" parameter from "postMessageWithLinkAndLinkToImage( Hashtable ht )", and it could work now. :eek:

    But before this time, I never succeed if I set "UIApplicationExitsOnSuspend" to checked, and try to log in when the FB app was pop up. It seems failed by my app was quit.

    Is there any way to log in without kicking my app out if the "UIApplicationExitsOnSuspend" is unchecked ? :(
     
    Last edited: Aug 29, 2011
  44. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @donlien, you will have to contact Facebook about their support for exiting on suspend. They only expose a login method via the SDK so what it does behind the scenes is in their hands.
     
  45. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Thank you for answer. ;)
     
  46. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Hi, Prime,

    Me again.

    I hate myself to ask you tons of questions, but there are things make me confuse.

    In the Doodle Jump, I see it can post message every time without leaving game if the "Facebook" setting in the Option is logged in.

    But, my app with Prime31 plugin is quite different with it.

    Every time I call "FacebookBinding.isLoggedIn()", it return false, so I login again with "FacebookBinding.loginWithRequestedPermissions( new string[] { "publish_stream", "offline_access" } )" or "FacebookBinding.login()", then plugin kick my app out, load FB app to log in, back to my app. Since the "UIApplicationExitsOnSuspend" is checked, so the app re-load again and "FacebookBinding.isLoggedIn()" return true until I quit my app.

    After app quit and re-launch by user tapping, the "FacebookBinding.isLoggedIn()" will return false again.

    It like a nightmare sticking me here for hours.

    Please help me !!!! :(

    How can I just log in only 1 time, and keep logged in just like Doodle Jump even if my app is quit ?

    Thanks a lot.
     
    Last edited: Aug 30, 2011
  47. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @donlien, I cannot reproduce what you are seeing. The demo scene has stayed logged in for me for weeks over many launches. Perhaps try not using UIApplicationExitsOnSuspend.
     
  48. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    Dear Prime, I've found the plugin will pop up this login dialog ( see attachment ) if I don't use "isLoggedIn()" to check login state, and use "showPostMessageDialogWithOptions( Hashtable options )" to post message directly.

    After I login by this dialog, it won't ask me to login anymore.

    These are my questions:

    1. Is this way to login recommended? (Or obsoleted ?)
    2. If this way to login is fine, could the Prime31 provide function to support it ?
    3. How come does the "isLoggedIn()" return false even if the "showPostMessageDialogWithOptions()" can work ? (Bug?)
     

    Attached Files:

  49. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @donlien, Facebook is in the process of deprecating any login that is not single sign on. You will need to contact them with regard to their timeline and recommendations.
     
  50. donlien

    donlien

    Joined:
    Apr 13, 2009
    Posts:
    229
    @Prime, I guess you mean this way to login is not recommended, right ? ( What the Doodle Jump did is not recommended, right ? )

    It's ok to me, but.... It seems not reasonable for an app to quit first log in every time.

    Could you please just tell me, how can I just call some function for login not to bother players too much ?

    Thank you.