예제 #1
0
        public async Task <WSAFacebookResponse <string> > GraphApiRead(string edge, Dictionary <string, string> parameters)
        {
            WSAFacebookResponse <string> graphApiReadResponse = new WSAFacebookResponse <string>();

            if (IsLoggedIn)
            {
                string fields = string.Empty;

                if (parameters != null && parameters.Count > 0)
                {
                    fields = parameters.Aggregate(string.Empty, (total, next) => total += (next.Key + "=" + next.Value + "&"));
                }

                string requestUri = string.Format("{0}{1}?{2}access_token={3}", WSAFacebookConstants.GraphApiUri, edge, fields, _accessToken);

                try
                {
                    HttpClient client = new HttpClient();

                    HttpResponseMessage response = await client.Get(requestUri);

                    string responseAsString = response.Data;

                    if (response.IsSuccessStatusCode)
                    {
                        graphApiReadResponse.Data    = responseAsString;
                        graphApiReadResponse.Success = true;
                    }
                    else
                    {
                        WSAFacebookError errorMessage = WSAFacebookError.FromDto(JsonUtility.FromJson <WSAFacebookErrorDto>(responseAsString));

                        if (errorMessage.Code == _authenticationErrorCode)
                        {
                            Logout(false);
                            errorMessage.AccessTokenExpired = true;
                        }

                        graphApiReadResponse.Success = false;
                        graphApiReadResponse.Error   = errorMessage;
                    }
                }
                catch
                {
                    graphApiReadResponse.Success = false;
                }
            }
            else
            {
                graphApiReadResponse.Success = false;
                graphApiReadResponse.Error   = new WSAFacebookError()
                {
                    AccessTokenExpired = true
                };
            }

            return(graphApiReadResponse);
        }
예제 #2
0
        public async Task <WSAFacebookResponse <bool> > HasUserLikedPage(string pageId)
        {
            WSAFacebookResponse <bool> hasUserLikedPageResponse = new WSAFacebookResponse <bool>();

            if (IsLoggedIn)
            {
                string requestUri = string.Format("{0}me/likes/{1}?access_token={2}", WSAFacebookConstants.GraphApiUri, pageId, _accessToken);

                try
                {
                    HttpClient client = new HttpClient();

                    HttpResponseMessage response = await client.Get(requestUri);

                    string responseAsString = response.Data;

                    if (response.IsSuccessStatusCode)
                    {
                        WSAFacebookDataResponse parsedResponse = JsonUtility.FromJson <WSAFacebookDataResponse>(responseAsString);

                        hasUserLikedPageResponse.Data    = parsedResponse.data != null;
                        hasUserLikedPageResponse.Success = true;
                    }
                    else
                    {
                        WSAFacebookError errorMessage = WSAFacebookError.FromDto(JsonUtility.FromJson <WSAFacebookErrorDto>(responseAsString));

                        if (errorMessage.Code == _authenticationErrorCode)
                        {
                            Logout(false);
                            errorMessage.AccessTokenExpired = true;
                        }

                        hasUserLikedPageResponse.Success = false;
                        hasUserLikedPageResponse.Error   = errorMessage;
                    }
                }
                catch
                {
                    hasUserLikedPageResponse.Success = false;
                }
            }
            else
            {
                hasUserLikedPageResponse.Success = false;
                hasUserLikedPageResponse.Error   = new WSAFacebookError()
                {
                    AccessTokenExpired = true
                };
            }

            return(hasUserLikedPageResponse);
        }
        public async Task <WSAFacebookResponse <WSAFacebookUser> > GetUserDetails()
        {
            WSAFacebookResponse <WSAFacebookUser> userDetailsResponse = new WSAFacebookResponse <WSAFacebookUser>();

            if (IsLoggedIn)
            {
                string fields = "id,age_range,birthday,email,first_name,gender,last_name,link,locale,name,picture,timezone";

                string requestUri = string.Format("{0}me?fields={1}&access_token={2}", WSAFacebookConstants.GraphApiUri, fields, _accessToken);

                try
                {
                    HttpClient client = new HttpClient();

                    HttpResponseMessage response = await client.Get(requestUri);

                    string responseAsString = response.Data;

                    if (response.IsSuccessStatusCode)
                    {
                        userDetailsResponse.Data    = WSAFacebookUser.FromDto(JsonUtility.FromJson <WSAFacebookUserDto>(responseAsString));
                        userDetailsResponse.Success = true;
                    }
                    else
                    {
                        WSAFacebookError errorMessage = WSAFacebookError.FromDto(JsonUtility.FromJson <WSAFacebookErrorDto>(responseAsString));

                        if (errorMessage.Code == _authenticationErrorCode)
                        {
                            Logout(false);
                            errorMessage.AccessTokenExpired = true;
                        }

                        userDetailsResponse.Success = false;
                        userDetailsResponse.Error   = errorMessage;
                    }
                }
                catch
                {
                    userDetailsResponse.Success = false;
                }
            }
            else
            {
                userDetailsResponse.Success = false;
                userDetailsResponse.Error   = new WSAFacebookError()
                {
                    AccessTokenExpired = true
                };
            }

            return(userDetailsResponse);
        }