Exemple #1
0
 public static void FBScreenShot(MonoBehaviour behaviour, Facebook.FacebookDelegate callbackSuccess = null, Facebook.FacebookDelegate callbackError = null)
 {
     try
     {
         behaviour.StartCoroutine(TakeScreenshot(result =>
         {
             if (!String.IsNullOrEmpty(result.Error))
             {
                 Debug.Log(result.Error);
             }
             else
             {
                 Debug.Log(result.Text);
                 IDictionary dict = Json.Deserialize(result.Text) as IDictionary;
                 if (dict != null && dict["id"] != null && callbackSuccess != null)
                 {
                     callbackSuccess(result);
                 }
                 else if (callbackError != null)
                 {
                     callbackError(result);
                 }
             }
         }));
     }
     catch (Exception e)
     {
         Debug.LogError(e.Message);
     }
 }
Exemple #2
0
 public static void FBDeleteRequest(string RequestId = "", Facebook.FacebookDelegate callback = null)
 {
     if (callback == null)
     {
         callback = result =>
         {
             Debug.Log(result.Text);
         };
     }
     if (RequestId.Length > 0)
     {
         try
         {
             FB.API("v2.2/" + RequestId + "?method=delete", Facebook.HttpMethod.GET, callback);
         }
         catch (Exception e)
         {
             Debug.LogError(e.Message);
         }
     }
     else
     {
         Debug.LogError("RequestId not valid");
     }
 }
Exemple #3
0
    private static IEnumerator TakeScreenshot(Facebook.FacebookDelegate callback)
    {
        yield return(new WaitForEndOfFrame());

        var width  = Screen.width;
        var height = Screen.height;
        var tex    = new Texture2D(width, height, TextureFormat.RGB24, false);

        // Read screen contents into the texture
        tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        tex.Apply();
        byte[] screenshot = tex.EncodeToPNG();

        var wwwForm = new WWWForm();

        wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
        wwwForm.AddField("message", "herp derp.  I did a thing!  Did I do this right?");

        try
        {
            FB.API("me/photos", Facebook.HttpMethod.POST, callback, wwwForm);
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
        }
    }
Exemple #4
0
 public void DeleteItemButton(Facebook.FacebookDelegate callback = null)
 {
     if (callback == null)
     {
         callback = result =>
         {
             if (!String.IsNullOrEmpty(result.Error))
             {
                 Debug.LogError(result.Error);
             }
             else
             {
                 //Cong tim khi nguoi dung nhan
                 AudioControl.AddHeart(1);
                 if (this != null)
                 {
                     Transform gridView = this.transform.parent;//This => Grid
                     gridView.GetComponent <UIGrid>().RemoveChild(this.transform);
                     Destroy(this.gameObject);
                 }
             }
         };
     }
     //Delete Request && Item
     if (requestId.Length > 0)
     {
         DFB.FBDeleteRequest(requestId, callback);
     }
     else
     {
         Debug.LogError("Request id not valid: " + requestId);
     }
 }
Exemple #5
0
 public static void FBAskForLife(string[] userIds, Facebook.FacebookDelegate callback = null)
 {
     if (callback == null)
     {
         callback = result =>
         {
             if (!String.IsNullOrEmpty(result.Error))
             {
                 Debug.Log(result.Error);
             }
             else
             {
                 Debug.Log(result.Text);
             }
         };
     }
     try
     {
         FB.AppRequest(DString.ASK_LIFE, Facebook.OGActionType.AskFor, DString.OBJID, userIds, DString.DATA_ASK_LIFE, "Ask for a life", callback);
     }
     catch (Exception e)
     {
         Debug.LogError(e.Message);
     }
 }
Exemple #6
0
 public static void CallFBPay(
     string product = "",
     Facebook.FacebookDelegate callback = null)
 {
     FB.Canvas.Pay(product, "purchaseitem", 1, null, null, null, null, null, callback);
     //FB.Canvas.Pay(PayProduct, "purchaseitem", 1, 1, 1, null, "10", "testCurrency", null);
 }
Exemple #7
0
 public static void FBLogin(Facebook.FacebookDelegate callback = null, String appPermision = "publish_actions, user_friends")
 {
     try
     {
         if (callback == null)
         {
             callback = result =>
             {
                 //Debug.Log(result.Text);
                 IDictionary dict = Json.Deserialize(result.Text) as IDictionary;
                 if (dict != null && dict["is_logged_in"] != null)
                 {
                     if ((bool)dict["is_logged_in"])
                     {
                         FB.API("v2.2/me", Facebook.HttpMethod.GET, rsl =>
                         {
                             IDictionary dict1 = Json.Deserialize(rsl.Text) as IDictionary;
                             if (dict1 != null && dict1["id"] != null)
                             {
                                 UserId   = "" + dict1["id"];
                                 UserName = "" + dict1["name"];
                             }
                         });
                     }
                 }
             };
         }
         FB.Login(appPermision, callback);
     }
     catch (Exception e)
     {
         Debug.LogError(e.Message);
     }
 }
Exemple #8
0
 private static void FBGetDeepLink(Facebook.FacebookDelegate callback = null)
 {
     if (callback == null)
     {
         callback = result =>
         {
             Debug.Log(result.Text);
         };
     }
     try
     {
         FB.GetDeepLink(callback);
     }
     catch (Exception e)
     {
         Debug.LogError(e.Message);
     }
 }
Exemple #9
0
 public static void FBGetUserFriend(int limit = 100, Facebook.FacebookDelegate callback = null)
 {
     if (callback == null)
     {
         callback = result =>
         {
             Debug.Log(result.Text);
         };
     }
     try
     {
         FB.API("/v2.2/me/friends?fields=id,name,picture&limit=" + limit, Facebook.HttpMethod.GET, callback);
     }
     catch (Exception e)
     {
         Debug.LogError(e.Message);
     }
 }
Exemple #10
0
 public static void FBGetScore(Facebook.FacebookDelegate callback = null)
 {
     if (callback == null)
     {
         callback = result =>
         {
             Debug.Log(result.Text);
         };
     }
     if (FB.IsLoggedIn)
     {
         try
         {
             FB.API("v2.2/" + FB.AppId + "/scores", Facebook.HttpMethod.GET, callback);
         }
         catch (Exception e)
         {
             Debug.LogError(e.Message);
         }
     }
 }
Exemple #11
0
    public static void FBSubmitScore(int Diem, Facebook.FacebookDelegate callback = null)
    {
        if (callback == null)
        {
            callback = result =>
            {
                Debug.Log(result.Text);
            };
        }
        if (FB.IsLoggedIn)
        {
            var query = new Dictionary <String, String>();
            query["score"] = Diem.ToString();

            try
            {
                FB.API("v2.2/me/scores", Facebook.HttpMethod.POST, callback, query);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }
        }
    }
    static void PostCallback(FBResult result)
    {
        //Debug.Log("Performing PostCallback: removing delegates");
        if(prevCB != null)
        {
            myLogger -= prevCB;
            prevCB = null;
        }
        myLogger -= PostCallback;

        //	Debug.Log("Cleared isJobPending to false");
        isJobPending = false;
    }
    /**************private**************/
    static void FBAPIQuery(string query, Facebook.FacebookDelegate userCallback, Facebook.HttpMethod httpMethod)
    {
        //****isJobPending = true;

        /*Facebook.FacebookDelegate myLogger = null;
        myLogger += new Facebook.FacebookDelegate(CompletedCallback);
        if(postCallback != null)
        {
            myLogger += new Facebook.FacebookDelegate(userCallback);
            myLogger += new Facebook.FacebookDelegate(userCallback);
            myLogger += new Facebook.FacebookDelegate(userCallback);
        }*/

        // Remove
        /*	if(prevCB != null)
        {
            myLogger -= prevCB;
            prevCB = null;
            //System.GC.Collect();
        }
        if(postCallback != null)
        {
            prevCB = postCallback;
            myLogger += postCallback;
        }
        myLogger += PostCallback;*/

        // If user supplies a callback, we need to clean it up in PostCallback
        if(userCallback != null)
        {
            prevCB = userCallback;
            myLogger += userCallback;
        }
        myLogger += PostCallback;

        FB.API(query, httpMethod, myLogger);
    }
    public static void PromptLogin(string accessesRequired = "", Facebook.FacebookDelegate userCallback = null)
    {
        if(isFBInit == false)
        {
            Debug.Log("Facebook Init() has not been called yet!");
            return;
        }

        if(isJobPending)
        {
            Debug.Log("Still waiting for response from previous Facebook call. Skipping PromptLogin command.");
            return;
        }

        if(FB.IsLoggedIn)
        {
            if(IsLoggedIn)
            {
                Debug.Log("User is already logged in. Log out first if you want to switch user.");
                return;
            }
            else
            {
                Debug.Log("User is already logged in, but permissions not granted at all (i.e. not even basic permissions granted. Requesting for basic permissions via Login again.");
                //todo: request permissions again

            }
        }

        /*if(postCallback == null)
        {
            //postCallback = DefaultCallback;
            Debug.Log("A proper login callback has to be given");
            return;
        }*/

        //****isJobPending = true;
        // Cleanup from previous call
        /*if(prevCB != null)
        {
            myLogger -= prevCB;
            prevCB = null;
        }
        //myLogger +=
        if(postCallback != null)
        {
            //myLogger += new Facebook.FacebookDelegate(postCallback);
            myLogger += postCallback;
            prevCB = postCallback;
        }*/
        if(userCallback != null)
        {
            prevCB = userCallback;
            myLogger += userCallback;
        }
        myLogger += PostCallback;

        if(accessesRequired.Trim().Length == 0)
        {
            // There was previously some bug in 5.0.3 that if it was empty it would not login
            accessesRequired = "basic_info";
        }

        Debug.Log("Attempting login/acquiring " + accessesRequired + " permission.");
        isJobPending = true;
        FB.Login(accessesRequired, myLogger);
    }
Exemple #15
0
 public void GetUserLike(string FacebookID, Facebook.FacebookDelegate Callback)
 {
 }
Exemple #16
0
    public static void FBRequestSelector(
        string TieuDeHopThoai = "",
        string NoiDungTinNhan = "Help",
        //Hiển thị các selectbox để chọn bạn bè(Tất cả, Những người đang chơi, Những người chưa chơi)
        string DanhSachLoc = "[\"all\",\"app_users\",\"app_non_users\"]",
        Facebook.FacebookDelegate callback = null)
    {
        string DuLieuLuuTru = "Test Du Lieu Luu Tru";
        //Danh sach loại trừ
        string DanhSachIdLoaiTru = "";
        string FriendSelectorMax = "";
        int?   SoLuongToiDa      = null;

        if (FriendSelectorMax != "")
        {
            try
            {
                SoLuongToiDa = Int32.Parse(FriendSelectorMax);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }
        }
        if (callback == null)
        {
            callback = result =>
            {
                Debug.Log(result.Text);
            };
        }
        // include the exclude ids
        string[]      MangIdLoaiTru   = (DanhSachIdLoaiTru == "") ? null : DanhSachIdLoaiTru.Split(',');
        List <object> DanhSachLocJson = null;

        if (!String.IsNullOrEmpty(DanhSachLoc))
        {
            try
            {
                DanhSachLocJson = Facebook.MiniJSON.Json.Deserialize(DanhSachLoc) as List <object>;
            }
            catch
            {
                throw new Exception("JSON Parse error");
            }
        }
        try
        {
            // include the exclude ids
            FB.AppRequest(
                NoiDungTinNhan,
                null,          //List id bạn bè chọn sẵn => bên Direct Request
                DanhSachLocJson,
                MangIdLoaiTru, //Danh sách bạn bè bị loại trừ ra khỏi lựa chọn
                SoLuongToiDa,
                DuLieuLuuTru,
                TieuDeHopThoai,
                callback
                );
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
        }
    }
Exemple #17
0
    ////Id ba?n be` ma` mi`nh muô´n viê´t lên tuo`ng
    //public string FeedToId = "";
    //public string FeedLink = "http://unity3d.com/";
    //public string FeedLinkName = "Link Name";
    //public string FeedLinkCaption = "Link Caption";
    //public string FeedLinkDescription = "Link Description";
    //public string FeedPicture = "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQFWLtAnaifE-6xU_lRwpErfufrznX8TOkdLql9Bcsn-sZiwwps";
    ////Tên link bên ca?nh nu´t chia se?
    //public string FeedActionName = "Feed Action Name";
    ////link bên ca?nh chia se?
    //public string FeedActionLink = "https://translate.google.com.vn/";
    //string FeedReference = "";
    //string FeedMediaSource = "";
    #endregion
    public static void FBFeed(Facebook.FacebookDelegate callbackSuccess = null,
                              Facebook.FacebookDelegate callbackError   = null,
                              Facebook.FacebookDelegate callbackFBError = null,
                              string IdNguoiNhan = "",
                              string TenGame     = "Link Name",
                              string LinkGame    = "http://unity3d.com/",
                              string LinkHinhAnh = "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQFWLtAnaifE-6xU_lRwpErfufrznX8TOkdLql9Bcsn-sZiwwps",
                              string MoTa1       = "",
                              string MoTa2       = "")
    {
        string TenLinkLienKet        = "";
        string LinkLienKet           = "";
        string FeedReference         = "";
        string FeedMediaSource       = "";
        bool   IncludeFeedProperties = false;
        Dictionary <string, string[]> FeedProperties = new Dictionary <string, string[]>();
        Dictionary <string, string[]> feedProperties = null;

        if (IncludeFeedProperties)
        {
            feedProperties = FeedProperties;
        }
        try
        {
            FB.Feed(
                toId: IdNguoiNhan,
                link: LinkGame,
                linkName: TenGame,
                linkCaption: MoTa1,
                linkDescription: MoTa2,
                picture: LinkHinhAnh,
                mediaSource: FeedMediaSource,
                actionName: TenLinkLienKet,
                actionLink: LinkLienKet,
                reference: FeedReference,
                properties: feedProperties,
                callback: result =>
            {
                if (!String.IsNullOrEmpty(result.Error))
                {
                    Debug.Log(result.Error);
                    if (callbackFBError != null)
                    {
                        callbackFBError(result);
                    }
                }
                else
                {
                    IDictionary dict = Json.Deserialize(result.Text) as IDictionary;
                    if (dict != null && dict["id"] != null)
                    {
                        if (callbackSuccess != null)
                        {
                            callbackSuccess(result);
                        }
                        //Debug.Log("FEED SUCCESS");
                    }
                    else
                    {
                        if (callbackError != null)
                        {
                            callbackError(result);
                        }
                        //Debug.Log("FEED CANCLE");
                    }
                }
            }
                );
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
        }
    }
Exemple #18
0
    public static void CallAppRequestAsDirectRequestMessage(string title, string message, string tofid, Facebook.FacebookDelegate Callback = null)
    {
        if (SceneGameOver.g_instance != null)
        {
            SceneGameOver.g_instance.buttonClickable = false;
        }

        if (tofid == "")
        {
            throw new ArgumentException("\"To Comma Ids\" must be specificed", "to");
        }

        if (Callback == null)
        {
            Callback = Callback_;
        }

        FB.AppRequest(
            message,          // message
            tofid.Split(','), // to
            "",               // filter
            null,             // excludeIds
            null,             // maxRecipients
            "",               // data
            title,            // title
            Callback          // callback
            );
    }
Exemple #19
0
    public static void FBRequestDirect(string[] DanhSachIdNguoiNhan = null, string TieuDe = "Tieu De", string NoiDungTinNhan = "Noi Dung Tin Nhan", Facebook.FacebookDelegate callback = null)
    {
        string        DuLieuLuuTru    = "Test Du Lieu Luu Tru";
        List <object> DanhSachLocJson = null;

        if (callback == null)
        {
            callback = result =>
            {
                Debug.Log(result.Text);
            };
        }
        try
        {
            if (DanhSachIdNguoiNhan == null)
            {
                //throw new ArgumentException("Danh Sach Nguoi Nhan Khong Ton Tai", DanhSachIdNguoiNhan);
                Debug.LogError("Danh sach nguoi nhan ko hop le " + DanhSachIdNguoiNhan);
            }
            FB.AppRequest(
                NoiDungTinNhan,
                DanhSachIdNguoiNhan,
                DanhSachLocJson,
                null,
                null,
                DuLieuLuuTru,
                TieuDe,
                callback
                );
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
        }
    }