コード例 #1
0
        public void ItShouldThrowInvalidOperationException(int number)
        {
            var httpMethod = (HttpMethod)number;

            Assert.Throws <InvalidOperationException>(
                () => FacebookUtils.ConvertToString(httpMethod));
        }
コード例 #2
0
        public void TheCountOfResultShouldBe0()
        {
            string whiteSpaceQueryString = "    ";
            var    result = FacebookUtils.ParseUrlQueryString(whiteSpaceQueryString);

            Assert.Equal(0, result.Count);
        }
コード例 #3
0
        public void ResultShouldNotBeNull()
        {
            string whiteSpaceQueryString = "    ";
            var    result = FacebookUtils.ParseUrlQueryString(whiteSpaceQueryString);

            Assert.NotNull(result);
        }
コード例 #4
0
        /// <summary>
        /// Gets the canvas login url
        /// </summary>
        /// <param name="returnUrlPath">
        /// The return Url Path.
        /// </param>
        /// <param name="cancelUrlPath">
        /// The cancel Url Path.
        /// </param>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="loginParameters">
        /// The parameters.
        /// </param>
        /// <returns>
        /// Returns the login url.
        /// </returns>
        public Uri GetLoginUrl(string returnUrlPath, string cancelUrlPath, string state, IDictionary <string, object> loginParameters)
        {
            var oauth = new FacebookOAuthClient
            {
                AppId = _settings.AppId
            };

            var oauthJsonState = PrepareCanvasLoginUrlOAuthState(returnUrlPath, cancelUrlPath, state, loginParameters);

            var oauthState            = FacebookWebUtils.Base64UrlEncode(Encoding.UTF8.GetBytes(oauthJsonState.ToString()));
            var mergedLoginParameters = FacebookUtils.Merge(loginParameters, null);

            mergedLoginParameters["state"] = oauthState;

            var appPath = _httpRequest.ApplicationPath;

            if (appPath != "/")
            {
                appPath = string.Concat(appPath, "/");
            }

            string redirectRoot = RedirectPath;

            var uriBuilder = new UriBuilder(CurrentCanvasUrl)
            {
                Path  = string.Concat(appPath, redirectRoot),
                Query = string.Empty
            };

            oauth.RedirectUri = uriBuilder.Uri;

            var loginUrl = oauth.GetLoginUrl(mergedLoginParameters);

            return(loginUrl);
        }
コード例 #5
0
ファイル: FacebookController.cs プロジェクト: rudrarajiv/aif
    private void SaveFriendsForMap(JSONArray dataFriends)
    {
        if (FacebookUtils.friendAvatarUrls != "")
        {
            return;
        }

        List <string> avatarUrlList   = new List <string>();
        List <int>    selectedIndexes = new List <int>();

        for (int i = 0; i < CommonConst.MAX_FRIEND_IN_MAP; i++)
        {
            if (selectedIndexes.Count >= dataFriends.Count)
            {
                break;
            }
            int index = 0;
            while (true)
            {
                index = UnityEngine.Random.Range(0, dataFriends.Count - 1);
                if (!selectedIndexes.Contains(index))
                {
                    selectedIndexes.Add(index);
                    break;
                }
            }
            string avatarUrl = dataFriends[index]["picture"]["data"]["url"].Value;
            avatarUrlList.Add(avatarUrl);
        }

        string avatarUrls = CUtils.BuildStringFromCollection(avatarUrlList);

        FacebookUtils.friendAvatarUrls = avatarUrls;

        // levels
        List <int> friendLevels = new List <int>();

        for (int i = 0; i < CommonConst.START_FRIEND_LEVELS.Length; i++)
        {
            friendLevels.Add(CommonConst.START_FRIEND_LEVELS[i]);
        }
        string strFriendLevels = CUtils.BuildStringFromCollection(friendLevels);

        FacebookUtils.friendLevels = strFriendLevels;

        // scores
        for (int i = 0; i < friendLevels.Count; i++)
        {
            List <int> scores = new List <int>();
            for (int level = 1; level < friendLevels[i]; level++)
            {
                int baseScore = CommonConst.GetTargetScore(level);
                int score     = UnityEngine.Random.Range(baseScore, baseScore * 3);
                score = (score / 10) * 10;
                scores.Add(score);
            }
            string strScores = CUtils.BuildStringFromCollection(scores);
            FacebookUtils.SetFriendScores(i, strScores);
        }
    }
コード例 #6
0
        internal IDictionary <string, object> PrepareCanvasLoginUrlOAuthState(string returnUrlPath, string cancelUrlPath, string state, IDictionary <string, object> loginParameters)
        {
            Contract.Ensures(Contract.Result <IDictionary <string, object> >() != null);

            var oauthJsonState = new JsonObject();

            // make it one letter character so more info can fit in.
            // r -> return_url_path
            // c -> cancel_url_path
            // s -> user_state

            var mergedParameters = FacebookUtils.Merge(null, loginParameters);

            if (mergedParameters.ContainsKey("state"))
            {
                // override the user state if present in the parameters.
                state = mergedParameters["state"] == null ? null : mergedParameters["state"].ToString();
            }

            if (!string.IsNullOrEmpty(state))
            {
                oauthJsonState["s"] = state;
            }

            if (string.IsNullOrEmpty(returnUrlPath))
            {
                oauthJsonState["r"] = CurrentCanvasPage.ToString();
            }
            else
            {
                if (IsRelativeUri(returnUrlPath))
                {
                    oauthJsonState["r"] = BuildCanvasPageUrl(returnUrlPath).ToString();
                }
                else
                {
                    oauthJsonState["r"] = returnUrlPath;
                }
            }

            if (string.IsNullOrEmpty(cancelUrlPath))
            {
                // if cancel url path is empty, get settings from facebook application.
                cancelUrlPath = _settings.CancelUrlPath;
            }

            if (!string.IsNullOrEmpty(cancelUrlPath))
            {
                if (IsRelativeUri(cancelUrlPath))
                {
                    oauthJsonState["c"] = BuildCanvasPageUrl(cancelUrlPath).ToString();
                }
                else
                {
                    oauthJsonState["c"] = cancelUrlPath;
                }
            }

            return(oauthJsonState);
        }
コード例 #7
0
        public static bool UserLikes(this Facebook facebook, string userId, string objectId)
        {
            AssertRequireAccessToken(facebook);

            if (userId.Equals("me()", StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException("User ID cannot be me().", userId);
            }

            var result = facebook.Query(
                string.Format("SELECT user_id FROM like WHERE user_id={0} AND object_id={1}",
                              userId, objectId));

            var jsonObj = FacebookUtils.FromJson(result);

            if (jsonObj.Count == 1)
            {
                var users = (IDictionary <string, object>)jsonObj["object"];
                if (users.Count == 1)
                {
                    if (users["user_id"].ToString().Equals(userId, StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #8
0
        public void ItShouldReturnTheEquivalentString(int number, string strHttpMethod)
        {
            var httpMethod = (HttpMethod)number;

            var result = FacebookUtils.ConvertToString(httpMethod);

            Assert.Equal(strHttpMethod, result);
        }
コード例 #9
0
        public void ItShouldDecodeCorrectly()
        {
            var queryString = "code=2.XeyH7lWz33itx1R86_uBeg__.3600.1294930800-100001327642026%7Ct8SsfSR2XI6yhBAkhX95J7p9hJ0";

            var result = FacebookUtils.ParseUrlQueryString(queryString);

            Assert.Equal("2.XeyH7lWz33itx1R86_uBeg__.3600.1294930800-100001327642026|t8SsfSR2XI6yhBAkhX95J7p9hJ0", result["code"]);
        }
コード例 #10
0
        /// <summary>
        /// Fetches the connections for given object.
        /// </summary>
        /// <param name="facebook"></param>
        /// <param name="id">Id of the object to fetch.</param>
        /// <param name="connectionName">Name of the connection.</param>
        /// <param name="parameters">List of arguments.</param>
        /// <returns>Returns the connections.</returns>
        public static T GetConnections <T>(this Facebook facebook, string id, string connectionName,
                                           IDictionary <string, string> parameters)
        {
            var jsonString = GetConnections(facebook, id, connectionName, parameters);

            FacebookUtils.ThrowIfFacebookException(jsonString);
            return(FacebookUtils.DeserializeObject <T>(jsonString));
        }
コード例 #11
0
        public void ResultIsFalse(string url)
        {
            var uri = new Uri(url);

            var result = FacebookUtils.IsUsingRestApi(null, uri);

            Assert.False(result);
        }
コード例 #12
0
        public void ResultShouldBeEmptyString()
        {
            var dict = new Dictionary <string, object>();

            var result = FacebookUtils.ToJsonQueryString(dict);

            Assert.Equal(string.Empty, result);
        }
        public void Error_descriptionShouldBeDecodedCorrectly()
        {
            var queryString = "error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.";

            var result = FacebookUtils.ParseUrlQueryString(queryString);

            Assert.Equal("The user denied your request.", result["error_description"]);
        }
        public void ReturnPathDoesNotStartWithForwardSlash()
        {
            string originalPathWithQueryString = "/me/likes?limit=3&offset=2";
            var    parameters = new Dictionary <string, object>();

            var path = FacebookUtils.ParseQueryParametersToDictionary(originalPathWithQueryString, parameters);

            Assert.NotEqual('/', path[0]);
        }
コード例 #15
0
        public void TheCountOfResultShouldBe0()
        {
            IDictionary <string, object> first  = null;
            IDictionary <string, object> second = null;

            var result = FacebookUtils.Merge(first, second);

            Assert.Equal(0, result.Count);
        }
コード例 #16
0
        public void TheResultShouldNotBeNull()
        {
            IDictionary <string, object> first  = null;
            IDictionary <string, object> second = null;

            var result = FacebookUtils.Merge(first, second);

            Assert.NotNull(result);
        }
コード例 #17
0
        /// <summary>
        /// Gets the specified post by id.
        /// </summary>
        /// <param name="facebook">
        /// The facebook.
        /// </param>
        /// <param name="postId">
        /// The id.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <returns>
        /// </returns>
        public static Post GetPost(this Facebook facebook, string postId, IDictionary <string, string> parameters)
        {
            var json = facebook.GetPostAsJson(postId, parameters);

            // Facebook seemed to have changed the api on 9/15/2010. small hack to DeserializeObject properly.
            json = json.Replace("\"comments\":[]", "\"comments\":{data:null,count:0}");

            return(FacebookUtils.DeserializeObject <Post>(json));
        }
コード例 #18
0
        public void ResultShouldNotBeNull()
        {
            var first  = new Dictionary <string, object>();
            var second = new Dictionary <string, object>();

            var result = FacebookUtils.Merge(first, second);

            Assert.NotNull(result);
        }
コード例 #19
0
        public void TheCountOfParameterIsEqualToTheCountOfQuerystring()
        {
            string urlWithQueryString = "http://graph.facebook.com/me/likes?limit=3&offset=2";
            var    parameters         = new Dictionary <string, object>();

            FacebookUtils.ParseQueryParametersToDictionary(urlWithQueryString, parameters);

            Assert.Equal(2, parameters.Count);
        }
コード例 #20
0
        public void ReturnPathDoesNotStartWithForwardSlash()
        {
            string url        = "http://graph.facebook.com/me/likes";
            var    parameters = new Dictionary <string, object>();

            var path = FacebookUtils.ParseQueryParametersToDictionary(url, parameters);

            Assert.NotEqual('/', path[0]);
        }
コード例 #21
0
        public void ReturnPathEqualsThePathWithoutQuerystring()
        {
            string originalPath = "/me/likes?limit=3&offset=2";
            var    parameters   = new Dictionary <string, object>();

            var path = FacebookUtils.ParseQueryParametersToDictionary(originalPath, parameters);

            Assert.Equal(path, "me/likes");
        }
コード例 #22
0
        public void CountOfParametersEquals2()
        {
            string path       = "/me/likes?limit=3&offset=2";
            var    parameters = new Dictionary <string, object>();

            FacebookUtils.ParseQueryParametersToDictionary(path, parameters);

            Assert.Equal(2, parameters.Count);
        }
        public void ExpiresInShouldBeDecodedCorrectly()
        {
            var queryString =
                "access_token=124973200873702%7C2.16KX_wTFlY2IAvWucsCKWA__.3600.1294927200-100001327642026%7CERLPsyFd8CP4ZI57VzAn0nl6WXo&expires_in=3699";

            var result = FacebookUtils.ParseUrlQueryString(queryString);

            Assert.Equal("3699", result["expires_in"]);
        }
コード例 #24
0
        public void CountOfParametersEquals0()
        {
            string path       = string.Empty;
            var    parameters = new Dictionary <string, object>();

            FacebookUtils.ParseQueryParametersToDictionary(path, parameters);

            Assert.Equal(0, parameters.Count);
        }
コード例 #25
0
        public void CountOfParameterIs0()
        {
            string url        = "http://graph.facebook.com/me/likes";
            var    parameters = new Dictionary <string, object>();

            FacebookUtils.ParseQueryParametersToDictionary(url, parameters);

            Assert.Equal(0, parameters.Count);
        }
コード例 #26
0
        public void TheParameterValuesAreEqualToTheQuerystrings()
        {
            string urlWithQueryString = "http://graph.facebook.com/me/likes?limit=3&offset=2";
            var    parameters         = new Dictionary <string, object>();

            FacebookUtils.ParseQueryParametersToDictionary(urlWithQueryString, parameters);

            Assert.Equal("3", parameters["limit"]);
            Assert.Equal("2", parameters["offset"]);
        }
コード例 #27
0
        public void ParameterValuesEqualToTheQuerystrings()
        {
            string path       = "/me/likes?limit=3&offset=2";
            var    parameters = new Dictionary <string, object>();

            FacebookUtils.ParseQueryParametersToDictionary(path, parameters);

            Assert.Equal("3", parameters["limit"]);
            Assert.Equal("2", parameters["offset"]);
        }
コード例 #28
0
        public void TheReturnPathEqualsPathWithoutUriHostAndDoesNotStartWithForwardSlash()
        {
            string urlWithQueryString = "http://graph.facebook.com/me/likes?limit=3&offset=2";
            string originalPathWithoutForwardSlashAndWithoutQueryString = "me/likes";
            var    parameters = new Dictionary <string, object>();

            var path = FacebookUtils.ParseQueryParametersToDictionary(urlWithQueryString, parameters);

            Assert.Equal(originalPathWithoutForwardSlashAndWithoutQueryString, path);
        }
コード例 #29
0
        public void ReturnPathEqualsPathWithoutUriHostAndDoesntStartWithForwardSlash()
        {
            string url = "http://graph.facebook.com/me/likes";
            string originalPathWithoutForwardSlash = "me/likes";
            var    parameters = new Dictionary <string, object>();

            var path = FacebookUtils.ParseQueryParametersToDictionary(url, parameters);

            Assert.Equal(originalPathWithoutForwardSlash, path);
        }
        public void ReturnPathEqualsThePathWithoutForwardSlash()
        {
            string originalPath            = "/me/likes";
            string pathWithoutForwardSlash = "me/likes";
            var    parameters = new Dictionary <string, object>();

            var path = FacebookUtils.ParseQueryParametersToDictionary(originalPath, parameters);

            Assert.Equal(pathWithoutForwardSlash, path);
        }