Search Unity

[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
    @Xanac, you didnt setup your app properly on Twitters website. Refer to the docs (http://prime31.com/unity/docs) paying special attention to the mention of the callback URL.
     
  2. Xantec

    Xantec

    Joined:
    Aug 2, 2011
    Posts:
    39
    Now it is saying this while debugging in XCode : SendMessage: object SocialNetworkingManager not found!
     
    Last edited: Dec 21, 2011
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Xantec, that just means you didn't add the SocialNetworkingManager prefab to your initial scene.
     
  4. Xantec

    Xantec

    Joined:
    Aug 2, 2011
    Posts:
    39
    What are the reasons for canUserTweet to be false? My app is set to read and right just to let you know.
     
  5. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
  6. Risine

    Risine

    Joined:
    Dec 10, 2009
    Posts:
    154
    I've got a problem with the SocialNetwork twitter plugin.
    It works fine when I login on Android, but not on Iphone.
    It says me : "unauthorized application, please use xauth"

    How can oauth login work fine on Android, and not on Iphone?

    Android :
    TwitterAndroid.init(m_twitterKey, m_twitterSecret);
    if (!TwitterAndroid.isLoggedIn()) TwitterAndroid.showLoginDialog();
    Iphone :
    TwitterBinding.init(m_twitterKey, m_twitterSecret);
    if (!TwitterBinding.isLoggedIn()) TwitterBinding.login(m_userName, m_userPass);
     
    Last edited: Jan 9, 2012
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Risene, you are attempting to use the Xauth login and don't have permission from Twitter to do so. You have to use the Oauth login with the showOauthLoginDialog method
     
  8. Risine

    Risine

    Joined:
    Dec 10, 2009
    Posts:
    154
    The thing is, how can It be that I have the permission via Android, and not IPhone?

    ...

    Ok, I see, I'm using XAuth on Iphone and OAuth on Android, that's it?
     
    Last edited: Jan 9, 2012
  9. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Risene, Twitter rejecting Xauth requests a while back and asked that everyone switch over to Oath. The Xauth login is only still in the iOS version for legacy support.
     
  10. Risine

    Risine

    Joined:
    Dec 10, 2009
    Posts:
    154
    Thanks for the info.
    Isn't it still needed on Iphone 3G ( opening a web dialog page using showOauthLoginDialog would close the app, wouldn't it? )
     
  11. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Risene, the dialog is shown in the app.
     
  12. Jay_Santos

    Jay_Santos

    Joined:
    May 31, 2011
    Posts:
    42
    I'm using the Social Network plugin and I have a question: I'd like to know if there is any way to obtain the uid of the Facebook user that is currently logged in through the plugin, instead of using a graph or rest call.

    Thank you,

    Jay_Santos
     
  13. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jay, I believe I already answered you via email but just in case anyone else wants the answer here it is: The only way Facebook has to get the UID of a user is through the Graph API. The plugin exposes the Graph API through the graphRequest method. I believe the "me" path is the one you want but to be sure you will want to consult Facebooks documentation.
     
  14. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Hi, I have a problem with
    Code (csharp):
    1. if (TwitterBinding.isTweetSheetSupported()) { //...do tweet with tweetsheet
    Unlike TwitterBinding.canUserTweet, It never seems to return True.

    What is the difference between these two? How can I check for the version of iOS on the device from Unity to make sure Tweet Sheet can be used?
     
  15. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @recluse, are you using the latest version of the plugin? It works fine for me on all our test devices.
     
  16. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    I only purchased it a couple of weeks ago, so I don't see how I couldn't be. I'm checking canUserTweet to display the TweetSheet, as isTweetSheetSupported doesn't ever give a positive. How does isTweetSheetSupported work? Is there a way in Unity I can find the iOS version?
     
  17. DarkJedi

    DarkJedi

    Joined:
    Apr 15, 2009
    Posts:
    48
    Hi recluse - yes I experienced this issue too with even quite recent versions of the SocialNetworking plugin. My workaround was to use "userCanTweet" as a check instead, as this checks the user has the latest iOS and has already configured a twitter account with it.

    Looking at the Objective-C code though I think the latest SocialNetworking plugin has "isTweetSheetSupported" checking the correct class now so I think downloading updating the plugin (even from just two weeks ago!) may well resolve this.

    Finally, check out the following for information on the user's device:
    SystemInfo.deviceModel
    SystemInfo.operatingSystem
    iPhoneSettings.generation

    Dan
     
  18. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Thanks Dan.

    I've got a problem recognizing the user successfully tweeted. This never fires to the debug...

    Code (csharp):
    1. function twitterPost()
    2.     {
    3.         Debug.Log( "Successfully posted to Twitter" );
    4.         // do other stuff after tweet posted...
    5.     }
    6.  
    I have added the twitterPost event listener, but this function is not getting called by it?

    How can I check the user tweeted successfully?
     
    Last edited: Feb 1, 2012
  19. DarkJedi

    DarkJedi

    Joined:
    Apr 15, 2009
    Posts:
    48
    Mike would need to clarify, but I believe the twitterPost and twitterPostFailed events are only raised after leveraging the postStatusUpdate method. I don't think there are success or failure events raised when using showTweetComposer - but I may be mistaken!
     
  20. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    ok, thanks for the info.

    Wondering how I tell when the user has posted via TweetSheet? I mean, I have to know when I can take them back to the game ;-)
     
  21. DarkJedi

    DarkJedi

    Joined:
    Apr 15, 2009
    Posts:
    48
    Ah, no need - Unity is paused while the user is composing their tweet (it shows as an overlay). When they have finished (either by posting or cancelling) Unity is un-paused and continues from the next line...
     
  22. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    if I post a tweet using postStatusUpdate, the tweet text won't be displayed unless I show it myself for the user, right?

    I'm considering using iPhoneUtils.isApplicationGenuine to check if my game has been hacked and then covertly tweet "I'm playing a cracked copy of..."

    Would be a nice little ploy to uncover people who didn't buy the app legally.
     
  23. DarkJedi

    DarkJedi

    Joined:
    Apr 15, 2009
    Posts:
    48
    Correct - assuming they've already been through the login or showOauthLoginDialog process to sign in and authorise your app at some point, of course...

    As to whether silently tweeting such a message would be a wise idea, I'm not so sure - I'd worry too much about false positives!
    Perhaps a "I love this game [iTunes link]" tweet as a subtle and less antagonistic alternative instead ;)

    As an aside - something that's not immediately apparent from the plugin's documentation is that clients that can take advantage of the iOS 5 tweet sheet composer don't need Twitter inits, logins or authentications from your app at all - the user is tweeting directly from their OS, not from your app (if that makes sense).
     
  24. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    My game already tweets "I love this game... " and in return the player gets an extra life each time they play.

    I figured tweeting a different message if the game had been cracked might wake up those people who don't care or know about indie game devs (and how every single legit download helps me to pay the rent) :)

    Yes, I just noticed as well that using Tweetsheet doesn't need the init, or login - cool.
     
  25. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485

    Seems like whatever I try to do afterwards I am getting EXC_BAD_ACCESS
     
  26. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @recluse, what steps are you taking to get a bad access? Can you post a stack trace (type "thread apply bt all" in the Xcode console while crashed)?
     
  27. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    @prime31 just mailed you a screen dump. It's happening in my playerManager start, so probably doing something stupid... If I load the title level after a successful tweet it doesn't crash.

    @DarkJedi Tweetsheet doesn't seem to pause for me like you said - my app is already loading the next level even before the tweet has been sent!

    EDIT: bollocks, I've found it. Undeclared variable in the inspector in my player manager. Major DOH!
     
    Last edited: Feb 1, 2012
  28. DarkJedi

    DarkJedi

    Joined:
    Apr 15, 2009
    Posts:
    48
    Oh, sorry mate - I assumed it worked similarly to the postStatusUpdate method in that respect, but clearly not! :eek:
     
  29. spartan

    spartan

    Joined:
    Mar 10, 2010
    Posts:
    174
    @prime31 Facebook login it's working great on an iPhone 4 with the facebook app using single sign on. On an iPhone 3G (without the facebook app installed), it shows the white window with the "x" button, the loading spin.. and then it gives "Facebook login failed", without showing the login form.

    ----------
    [solved]: the old iPhone 3G was with wrong Date.
     
    Last edited: Feb 4, 2012
  30. liampc

    liampc

    Joined:
    Feb 5, 2012
    Posts:
    16
    As for the catching pirates topic, I wouldn't suggest advertising that your game has been cracked and is available for free. Although, you could just include some strange string of characters hash-tagged at the end of the tweet. That way you could search twitter, and as long as it's not a common string then you should have a nice list of pirates waiting for you.


    Whether you can do anything about them or not is another thing..
     
  31. Milad

    Milad

    Joined:
    Aug 17, 2010
    Posts:
    67
    Hi Prime,

    i can not build my app.i have this error : Framework not found Twitter.

    SDK : 4.2 (i want to build with 4.2 version)
    Unity : last version Pro

    Please help.thanks.
     
  32. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Milad, your iOS SDK is out of date. You should be building against iOS 5 which contains the Twitter.framework.
     
  33. SebastianVargas

    SebastianVargas

    Joined:
    Jun 29, 2009
    Posts:
    18

    FOR EVERYONE THAT HAS ISSUES WITH SCORES (Kev,and others)


    I had the same issue after many many days i finally thanks God, i was able to submit a score for facebook leadeboard!.

    The thing is that you have to send not the user access token (which is the default send by prime in xcode) but the app access token.

    I modify the facebook.m, facebookbinding.cs to avoid that the included access token, replace the token sent as parameter in unity (as kev was doing) and in the binding create an alternate method.

    Also it has to use FacebookBinding.loginWithRequestedPermissions(new string[]{"publish_actions, user_games_activity, friends_games_activity"});

    Set on de FB dev page, on configuration/advanced: Login to Web and not to Mobile/desktop

    Note that the app access token has to be captured in xcode (i don't know how ) but temporally you can use the APPID|APPSECRETID as the token.

    I think that is all. If anybody needs some help to get scores or achievements working please tell me.


    PD. Prime could you make this stuff well done and send us in the next update please?
     
  34. Masashi-Wada

    Masashi-Wada

    Joined:
    Jul 6, 2010
    Posts:
    89
    Hi prime31!

    I worry about action of SNS plug-in.

    I set an Orientation setup of my application to AutoRotation.
    It is Landscape Left/Right which was permitted by this AutoRotation.
    I showed as a screen of LandscapeLeft first. Next, the TwitterLogin dialog was shown on the screen.

    If a TwitterLogin dialog is closed as it is, a screen will change to LandscapeRight.
    In the meantime, I am not rotating that of my iPhone.
    It was able to see not only in my application but in the sample code project of plug-in.
    And this is not seen by FacebookLogin.
    Is there any way I solve this view problem?


    used version SocialNetworking_2012-01-28
    Unity 3.4.2f3 pro ( with MacOS iOS build )
    iOS SDK 5.0
    Device iPhone4S (5.0.1)
     
  35. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Is there a way to get confirmation that a tweet was successfully posted using TweetSheet?
     
  36. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Masahashi, I cannot reproduce what you are seeing. If you have the Player Settings set to autorotate and the animated checkbox is checked Unity will obey the device orientation. If you change the orientation manually anywhere in code you will break the auto orientation.


    @recluse, there is currently no event for closing the Tweet Sheet. The reason we avoided adding it is because it either requires weak linking an entire base library (not a good practice) or requiring iOS 4+. There are still folks who are supporting iOS 3 believe it or not se we didn't yet add the event.
     
  37. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    ok, I'm using oldskool tweeting now, but I'm not seeing TwitterPost() called in my script after successful posting. I have set up the event listeners in the same script, so shouldn't this function get fired after a post?

    Code (csharp):
    1. function twitterPost() : void
    2.     {
    3.         Debug.Log( "Successfully posted to Twitter" );
    4.         tweetPosted=true;
    5.        
    6.     }
    7.  
     
  38. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @recluse, I don't see you adding the event listener anywhere. See the *EventListener file for examples of how to listen to all the available events.
     
  39. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    it's added in the same script - I didn't post it all cos its long...
     
  40. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    full script is:

    Code (csharp):
    1. #pragma strict
    2.     #pragma implicit
    3.     #pragma downcast
    4.    
    5.     import System.Collections.Generic;
    6.    
    7.     private var isLoggedIn : boolean = false;
    8.     private var useTweetSheet : boolean = false;
    9.  
    10.     private var screenshotFilename : String = "ScreenGrab.png";
    11.     static var tweetStr : String ="tweet text here";
    12.     var myGUISkin : GUISkin;
    13.     private var tweetPosted : boolean = false;
    14.  
    15.    
    16.     function OnEnable () {
    17.        
    18.         SocialNetworkingManager.twitterLogin += twitterLogin;
    19.         SocialNetworkingManager.twitterLoginFailed += twitterLoginFailed;
    20.         SocialNetworkingManager.twitterPost += twitterPost;
    21.         SocialNetworkingManager.twitterPostFailed += twitterPostFailed;
    22.         SocialNetworkingManager.twitterHomeTimelineReceived += twitterHomeTimelineReceived;
    23.         SocialNetworkingManager.twitterHomeTimelineFailed += twitterHomeTimelineFailed;
    24.         SocialNetworkingManager.twitterRequestDidFinishEvent += twitterRequestDidFinishEvent;
    25.         SocialNetworkingManager.twitterRequestDidFailEvent += twitterRequestDidFailEvent;
    26.  
    27.     }
    28.    
    29.    
    30.     function Start () {
    31.        
    32.        
    33.         Application.CaptureScreenshot("ScreenGrab.png");
    34.        
    35.         // then you want to post via status update!
    36.    
    37.         TwitterBinding.init( "xxxxxxxxx", "xxxxxxxxxxx" ); 
    38.        
    39.         if (!TwitterBinding.isLoggedIn()) TwitterBinding.showOauthLoginDialog(); // are we logged in? Show Login if not
    40.  
    41.         isLoggedIn = TwitterBinding.isLoggedIn();
    42.    
    43.        
    44.         while (isLoggedIn == false) {
    45.            
    46.             if(TwitterBinding.isLoggedIn()) isLoggedIn =true;  
    47.             yield; 
    48.         }
    49.        
    50.         Debug.Log( "Twitter is logged in: " + isLoggedIn );
    51.                
    52.     }
    53.    
    54.     function OnDisable () {
    55.        
    56.         SocialNetworkingManager.twitterLogin -= twitterLogin;
    57.         SocialNetworkingManager.twitterLoginFailed -= twitterLoginFailed;
    58.         SocialNetworkingManager.twitterPost -= twitterPost;
    59.         SocialNetworkingManager.twitterPostFailed -= twitterPostFailed;
    60.         SocialNetworkingManager.twitterHomeTimelineReceived -= twitterHomeTimelineReceived;
    61.         SocialNetworkingManager.twitterHomeTimelineFailed -= twitterHomeTimelineFailed;
    62.         SocialNetworkingManager.twitterRequestDidFinishEvent -= twitterRequestDidFinishEvent;
    63.         SocialNetworkingManager.twitterRequestDidFailEvent -= twitterRequestDidFailEvent;
    64.  
    65.     }
    66.  
    67.    
    68.            
    69.    
    70.    
    71.     function OnGUI () {
    72.        
    73.         GUI.skin = myGUISkin;
    74.        
    75.                 if( GUI.Button( new Rect( 0, Screen.height/2, Screen.width, 64 ), "Post Tweet!" ) ) {
    76.  
    77.                 TwitterBinding.postStatusUpdate("#Nowplaying #iOS #game blah blah" + Time.deltaTime);
    78.                
    79.                 Debug.Log("Posted");
    80.                 ExitTweeting();
    81.  
    82.             }
    83.         }
    84.    
    85.     function ExitTweeting () {
    86.        
    87.         while (!tweetPosted) {
    88.         yield;
    89.         }
    90.         PlayerPrefs.SetInt("tweets", 1);
    91.         Global.tweets=1;
    92.         yield new WaitForSeconds(3);
    93.         Global.Lives+=1;
    94.         Debug.Log("loading next level");
    95.         Application.LoadLevel("GiveHeart");
    96.     }
    97.    
    98.     // Twitter events
    99.    
    100.     function twitterLogin()
    101.     {
    102.         Debug.Log( "Successfully logged in to Twitter" );
    103.     }
    104.    
    105.    
    106.     function twitterLoginFailed( error : String )
    107.     {
    108.         Debug.Log( "Twitter login failed: " + error );
    109.     }
    110.    
    111.  
    112.     function twitterPost() : void
    113.     {
    114.         Debug.Log( "Successfully posted to Twitter" );
    115.         tweetPosted=true;
    116.        
    117.     }
    118.    
    119.  
    120.     function twitterPostFailed( error : String )
    121.     {
    122.         Debug.Log( "Twitter post failed: " + error );
    123.         Application.LoadLevel("Title");
    124.     }
    125.  
    126.  
    127.     function twitterHomeTimelineFailed( error : String )
    128.     {
    129.         Debug.Log( "Twitter HomeTimeline failed: " + error );
    130.     }
    131.    
    132.    
    133.     function twitterHomeTimelineReceived( result : ArrayList ) : void
    134.     {
    135.         Debug.Log( "received home timeline with tweet count: " + result.Count );
    136.     }
    137.    
    138.    
    139.     function twitterRequestDidFailEvent( error : String )
    140.     {
    141.         Debug.Log( "twitterRequestDidFailEvent: " + error );
    142.     }
    143.    
    144.    
    145.     function twitterRequestDidFinishEvent( result : Object )
    146.     {
    147.         if( result != null )
    148.             Debug.Log( "twitterRequestDidFinishEvent: " + result.GetType().ToString() );
    149.         else
    150.             Debug.Log( "twitterRequestDidFinishEvent with no data" );
    151.     }
    152.    
    153.    
     
  41. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Strangely, after adding a Debug.Log to the SocialNetworkingManager script...

    Code (csharp):
    1. public void twitterPostSucceeded( string empty )
    2.     {
    3.         if( twitterPost != null )
    4.             twitterPost();
    5.             Debug.Log("twitter posted successfully!!!");
    6.     }
    7.  
    my twitterPost function is firing.
     
  42. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @recluse, that all looks about right to me. What do you see in the console? Do you have the *Manager prefab in your initial loading scene?
     
  43. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Well, it all seems to be working now - I'm getting twitterPost() firing when posting is successful.

    I'm also getting failed posts reported too.

    One more Q: when i add a URL to my tweet text, i.e http://itunes.com/apps/myappname, it doesn't seem to get turned into a clickable link by Twitter. Am I missing something? I'm sure it worked when I did it via tweetsheet.
     
  44. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @recluse, Twitter is supposed to wrap all links in t.co shortened versions. The plugin doesn't do anything special with them.
     
  45. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    yeah, I realize it's not the plugin end. Just wondering why my http:// isn't getting wrapped.
     
  46. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    btw, is there a reason you recommend loading the *Manager prefab in the initial scene? I do that with the GameCenter plugin but I am loading the NetworkManager in its own scene (as all tweeting is done in this scene only). Should I load NM in the initial scene too?
     
  47. pysavard

    pysavard

    Joined:
    Feb 13, 2012
    Posts:
    2
    Hi,

    I've been trying to post an image from my Android Phone but nothing works for me right now...

    I tried with the postImage and graphRequest function and both of them return me errors. I'm pretty sure my image path is right and my image is not that big (I've seen a limitation of 720px)...

    Here is a sample of my code with the postImage function
    Code (csharp):
    1.  
    2. void authDidSucceedEvent()
    3. {
    4.      Texture2D myTexture = new Texture2D(Screen.width / 2, Screen.height / 2);
    5.      myTexture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
    6.      myTexture.Apply();
    7.  
    8.      FacebookAndroid.postImage(myTexture.EncodeToPNG(), "test");
    9. }
    10.  
    Error Message : "An unknown error occurred"
    Error Code : 1

    --------

    With the graphRequest function

    Code (csharp):
    1.  
    2. void authDidSucceedEvent()
    3. {
    4.     Dictionary<string, string> dict = new Dictionary<string, string>();
    5.     dict.Add("access_token", FacebookAndroid.getSessionToken());
    6.     dict.Add("message", "test message");
    7.     dict.Add("picture", "http://www.thomasstockwell.com/wp-content/uploads/2009/01/generic_cola_can_jewel.jpg");
    8.     dict.Add("source", "http://www.thomasstockwell.com/wp-content/uploads/2009/01/generic_cola_can_jewel.jpg");
    9.     dict.Add("link", "http://www.google");
    10.     dict.Add("name", "test");
    11.     FacebookAndroid.graphRequest("photos", "POST", dict);
    12. }
    13.  
    Error Message : "(#324) Requires upload file"
    Error Type : OAuthException

    any help would be appreciated!

    Thank You!
     
  48. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @pysavard, checkout the demo scene for the details. You can't post PNG's encoded with Unity directly due to a bug with the PNG encoder. You have to use the JPG encoder that is included with the plugin.
     
  49. pysavard

    pysavard

    Joined:
    Feb 13, 2012
    Posts:
    2
    Doh!! I've forgot the demo scene... thank you for the tips, I'll check that right now...

    PY
     
  50. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    I'm getting this warning suddenly...

    Edit: bah, i see what i did!