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

Facebook SDK - Send lives between users - FB.API() problem

Discussion in 'Scripting' started by jsr2k1, Nov 14, 2014.

  1. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    115
    Hello everyone,

    I want to send lives between players. I'm trying to get the object ID with FB.API but I can't.
    This is my code:

    Dictionary<string, string> formData = new Dictionary<string, string>();
    formData["og:url"] = "http://samples.ogp.me/746045498766635";
    formData["og:title"] = "Sample Life";
    formData["og:type"] = "bubbleparadisetwo:life";
    formData["og:image"] = "https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png";
    formData["og:description"] = "";
    formData["fb:app_id"] = "730922200278965";
    FB.API("/app/objects/bubbleparadisetwo:life", HttpMethod.POST, SendLiveCallback, formData);

    And the result is:
    "java.io.FileNotFoundException: https://graph.facebook.com/app/objects/bubbleparadisetwo:life"

    The object type "Life" has been created in the Open Graph page.
    The login to Facebook is: FB.Login("public_profile,email,user_friends,publish_actions", AuthCallback);

    Can you help me? Thanks in advance,

    Joel
     
  2. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    115
    Solved!

    Dictionary<string, string> formData = new Dictionary<string, string>();
    formData["og:title"] = "Sample Life";
    formData["og:type"] = "bubbleparadisetwo:life";
    formData["fb:app_id"] = "730922200278965";
    Dictionary<string, string> formDic = new Dictionary<string, string>();
    formDic["object"] = Facebook.MiniJSON.Json.Serialize(formData);
    FB.API("me/objects/bubbleparadisetwo:life", HttpMethod.POST, SendLiveCallback, formDic);

    ------------------------------------------------

    The question now is how to ask for lives???

    I can use FB.AppRequest with OGActionType.AskFor
    ... but what ObjectId then if it's not yet created?
     
  3. Saddamjit_Singh

    Saddamjit_Singh

    Joined:
    Dec 4, 2015
    Posts:
    22
    I am doing ass you said-

    Code (CSharp):
    1. public void ObjectManagement()
    2.         {
    3.             Dictionary<string,string> formData = new Dictionary<string,string>();
    4.             formData["og:title"] = "coins";
    5.             formData["og:type"] = "game";
    6.             formData["fb:app_id"] = "921871194580745";  
    7.             Dictionary<string,string> formDic = new Dictionary<string,string>();
    8.             formDic["object"] = Facebook.MiniJSON.Json.Serialize(formData);
    9.             Debug.LogError ("formDic : " + formDic.Values);
    10.  
    11.             FB.API("me/objects/coins", HttpMethod.POST, CreateFBLifeCallback, formDic);
    12.         }
    13.         public void CreateFBLifeCallback(IGraphResult result)
    14.         {
    15.             if (!string.IsNullOrEmpty(result.Error))
    16.             {
    17.                 Debug.LogError("Error during object create call! " + result.Error);
    18.             }
    19.             else if (FB.IsLoggedIn)
    20.             {
    21.                 Debug.LogError("ok during object create call! " + result.Error);
    22.  
    23.             }
    24.         }

    and getting no result
     
  4. Saddamjit_Singh

    Saddamjit_Singh

    Joined:
    Dec 4, 2015
    Posts:
    22
    Hi,

    Bro, i need your help really very much. I am stuck in object formation (Open Graph) for sending and asking lives via Facebook from Unity.

    Till now i have understood that Facebook has changed it's API and now we can only use default object types.
    To create an object and to fetch it's object ID, i am using the code written below-

    Code (CSharp):
    1. private static void GetOpenGraphObjectID()
    2.         {
    3.             var formDict = new Dictionary<string, string>()
    4.             {
    5.                 {"title", "AskForCoins"},
    6.                 {"type", "product.item"},
    7.                 {"app_id", "921871194580745"}
    8.             };
    9.             var formData = new Dictionary<string, string>() { { "object", Facebook.MiniJSON.Json.Serialize(formDict) } };
    10.             Debug.LogError (formDict.Values);
    11.             FB.API("/me?objects/product.item", HttpMethod.POST, CreateFBLifeCallback, formData);
    12.         }
    13.  
    14.         private static void CreateFBLifeCallback(IGraphResult result)
    15.         {
    16.             if (!string.IsNullOrEmpty(result.Error))
    17.             {
    18.                 Debug.LogError("Error during object create call! " + result.Error);
    19.             }
    20.             else
    21.             {
    22.  
    23.                 Debug.LogError("result "+result.ResultDictionary.Values);
    24.                 object myID;
    25.                 if (result.ResultDictionary.TryGetValue ("id", out myID)) {
    26.                     Debug.LogError ("myID "+myID);
    27.                 }
    28.  
    29.             }
    30.         }
    But i am getting no object ID in return. I am only using this way to create object and i am not using Object Browser window to create object. Please help in figuring out the issue .