コード例 #1
0
        /// <summary>
        /// Gets an app access token for for the application. The <see cref="ClientId"/> and <see cref="ClientSecret"/>
        /// properties must be specified for the OAuth client.
        /// </summary>
        /// <returns>Returns an instance of <see cref="FacebookTokenResponse"/> representing the response.</returns>
        public FacebookTokenResponse GetAppAccessToken()
        {
            // Some validation
            if (String.IsNullOrWhiteSpace(Version))
            {
                throw new PropertyNotSetException("Version");
            }
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException("ClientId");
            }
            if (String.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException("ClientSecret");
            }

            // Initialize the query string
            IHttpQueryString query = new SocialHttpQueryString();

            query.Add("client_id", ClientId);
            query.Add("client_secret", ClientSecret);
            query.Add("grant_type", "client_credentials");

            // Make the call to the API
            SocialHttpResponse response = SocialUtils.Http.DoHttpGetRequest("https://graph.facebook.com/" + Version + "/oauth/access_token", query);

            // Parse the response
            return(FacebookTokenResponse.ParseResponse(response));
        }
コード例 #2
0
        /// <summary>
        /// Attempts to renew a user access token. The specified <code>currentToken</code> must be valid.
        /// </summary>
        /// <param name="currentToken">The current access token.</param>
        /// <returns>Returns an instance of <see cref="FacebookTokenResponse"/> representing the response.</returns>
        public FacebookTokenResponse RenewAccessToken(string currentToken)
        {
            // Some validation
            if (String.IsNullOrWhiteSpace(Version))
            {
                throw new PropertyNotSetException("Version");
            }
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException("ClientId");
            }
            if (String.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException("ClientSecret");
            }
            if (String.IsNullOrWhiteSpace(currentToken))
            {
                throw new ArgumentNullException("currentToken");
            }

            // Initialize the query string
            NameValueCollection query = new NameValueCollection {
                { "grant_type", "fb_exchange_token" },
                { "client_id", ClientId },
                { "client_secret", ClientSecret },
                { "fb_exchange_token", currentToken }
            };

            // Make the call to the API
            SocialHttpResponse response = SocialUtils.Http.DoHttpGetRequest("https://graph.facebook.com/" + Version + "/oauth/access_token", query);

            // Parse the response
            return(FacebookTokenResponse.ParseResponse(response));
        }
コード例 #3
0
        /// <summary>
        /// Attempts to renew a user access token. The specified <paramref name="currentToken"/> must be valid.
        /// </summary>
        /// <param name="currentToken">The current access token.</param>
        /// <returns>An instance of <see cref="FacebookTokenResponse"/> representing the response.</returns>
        public FacebookTokenResponse RenewAccessToken(string currentToken)
        {
            // Some validation
            if (string.IsNullOrWhiteSpace(Version))
            {
                throw new PropertyNotSetException(nameof(Version));
            }
            if (string.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException(nameof(ClientId));
            }
            if (string.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException(nameof(ClientSecret));
            }
            if (string.IsNullOrWhiteSpace(currentToken))
            {
                throw new ArgumentNullException(nameof(currentToken));
            }

            // Initialize the query string
            IHttpQueryString query = new HttpQueryString();

            query.Add("grant_type", "fb_exchange_token");
            query.Add("client_id", ClientId);
            query.Add("client_secret", ClientSecret);
            query.Add("fb_exchange_token", currentToken);

            // Make the call to the API
            IHttpResponse response = HttpUtils.Http.DoHttpGetRequest("https://graph.facebook.com/" + Version + "/oauth/access_token", query);

            // Parse the response
            return(FacebookTokenResponse.ParseResponse(response));
        }
コード例 #4
0
        /// <summary>
        /// Exchanges the specified authorization code for an access token.
        /// </summary>
        /// <param name="authCode">The authorization code received from the Facebook OAuth dialog.</param>
        /// <returns>Returns an instance of <see cref="FacebookTokenResponse"/> representing the response.</returns>
        public FacebookTokenResponse GetAccessTokenFromAuthCode(string authCode)
        {
            // Some validation
            if (String.IsNullOrWhiteSpace(Version))
            {
                throw new PropertyNotSetException("Version");
            }
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException("ClientId");
            }
            if (String.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException("ClientSecret");
            }
            if (String.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException("RedirectUri");
            }
            if (String.IsNullOrWhiteSpace(authCode))
            {
                throw new ArgumentNullException("authCode");
            }

            // Initialize the query string
            IHttpQueryString query = new SocialHttpQueryString();

            query.Add("client_id", ClientId);
            query.Add("redirect_uri", RedirectUri);
            query.Add("client_secret", ClientSecret);
            query.Add("code", authCode);

            // Make the call to the API
            SocialHttpResponse response = SocialUtils.Http.DoHttpGetRequest("https://graph.facebook.com/" + Version + "/oauth/access_token", query);

            // Parse the response
            return(FacebookTokenResponse.ParseResponse(response));
        }