Search Unity

Unity Facebook SDK: FB.Feed not posting

Discussion in 'Editor & General Support' started by jerryberry, Aug 4, 2014.

  1. jerryberry

    jerryberry

    Joined:
    Feb 12, 2014
    Posts:
    6
    Hi!
    I finished my game. Now I want to make it social. Posting to twitter is easy, but I have a problem with facebook.

    I created an app on facebook dev, I have key-hash, key-store, I don't have any errors in console. I made enviroment variables with paths to JDK and OpenSSL. Maybe there's something wrong with my code (it's from SDK example) but I don't know what.

    This script is attached to NGUI button. In editor it works but on device it only asks for login and permission. Then nothing happens.

    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Linq;
    6.  
    7. public sealed class FacebookShare : MonoBehaviour {
    8. #region FB.Init() example
    9.  
    10. private bool isInit = false;
    11.  
    12. void Awake ()
    13. {
    14.     CallFBInit();
    15. }
    16.  
    17. private void CallFBInit()
    18. {
    19.     FB.Init(OnInitComplete, OnHideUnity);
    20. }
    21.  
    22. private void OnInitComplete()
    23. {
    24.     Debug.Log("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
    25.     isInit = true;
    26. }
    27.  
    28. private void OnHideUnity(bool isGameShown)
    29. {
    30.     Debug.Log("Is game showing? " + isGameShown);
    31. }
    32.  
    33. #endregion
    34.  
    35. #region FB.Login() example
    36.  
    37. private void CallFBLogin()
    38. {
    39.     FB.Login("email,publish_actions", LoginCallback);
    40. }
    41.  
    42. void LoginCallback(FBResult result)
    43. {
    44.     if (result.Error != null)
    45.         lastResponse = "Error Response:\n" + result.Error;
    46.     else if (!FB.IsLoggedIn)
    47.     {
    48.         lastResponse = "Login cancelled by Player";
    49.     }
    50.     else
    51.     {
    52.         lastResponse = "Login was successful!";
    53.     }
    54. }
    55.  
    56. private void CallFBLogout()
    57. {
    58.     FB.Logout();
    59. }
    60. #endregion
    61.  
    62. #region FB.Feed() example
    63.  
    64. public string FeedToId = "";
    65. public string FeedLink = "";
    66. public string FeedLinkName = "";
    67. public string FeedLinkCaption = "";
    68. public string FeedLinkDescription = "";
    69. public string FeedPicture = "";
    70. public string FeedMediaSource = "";
    71. public string FeedActionName = "";
    72. public string FeedActionLink = "";
    73. public string FeedReference = "";
    74. public bool IncludeFeedProperties = false;
    75. private Dictionary<string, string[]> FeedProperties = new Dictionary<string, string[]>();
    76.  
    77. private void CallFBFeed()
    78. {
    79.     Dictionary<string, string[]> feedProperties = null;
    80.     if (IncludeFeedProperties)
    81.     {
    82.         feedProperties = FeedProperties;
    83.     }
    84.     FB.Feed(
    85.         toId: FeedToId,
    86.         link: FeedLink,
    87.         linkName: FeedLinkName,
    88.         linkCaption: FeedLinkCaption,
    89.         linkDescription: FeedLinkDescription,
    90.         picture: FeedPicture,
    91.         mediaSource: FeedMediaSource,
    92.         actionName: FeedActionName,
    93.         actionLink: FeedActionLink,
    94.         reference: FeedReference,
    95.         properties: feedProperties,
    96.         callback: Callback
    97.         );
    98. }
    99.  
    100. #endregion
    101. public string ApiQuery = "";
    102. private string lastResponse = "";
    103. private Texture2D lastResponseTexture;
    104.  
    105. void Callback(FBResult result)
    106. {
    107.     lastResponseTexture = null;
    108.     // Some platforms return the empty string instead of null.
    109.     if (!String.IsNullOrEmpty(result.Error))
    110.         lastResponse = "Error Response:\n" + result.Error;
    111.     else if (!ApiQuery.Contains("/picture"))
    112.         lastResponse = "Success Response:\n" + result.Text;
    113.     else
    114.     {
    115.         lastResponseTexture = result.Texture;
    116.         lastResponse = "Success Response:\n";
    117.     }
    118. }
    119.  
    120. void OnClick ()
    121. {
    122.     CallFBLogin();
    123.     CallFBFeed();
    124. }
    125. }