Esempio n. 1
0
        /// <summary>
        /// Posts a link with the specified options.
        /// </summary>
        /// <param name="identifier">The identifier of user, page or similar.</param>
        /// <param name="options">The options for the link.</param>
        public string PostLink(string identifier, FacebookPostLinkOptions options)
        {
            // Construct the query string
            NameValueCollection query = new NameValueCollection();

            if (!String.IsNullOrWhiteSpace(options.Link))
            {
                query.Add("link", options.Link);
            }
            if (!String.IsNullOrWhiteSpace(options.Description))
            {
                query.Add("description", options.Description);
            }
            if (!String.IsNullOrWhiteSpace(options.Message))
            {
                query.Add("message", options.Message);
            }
            if (!String.IsNullOrWhiteSpace(options.Name))
            {
                query.Add("name", options.Name);
            }
            if (!String.IsNullOrWhiteSpace(options.Caption))
            {
                query.Add("caption", options.Caption);
            }
            query.Add("access_token", Client.AccessToken);

            // Make the call to the API
            return(SocialUtils.DoHttpPostRequestAndGetBodyAsString("https://graph.facebook.com/" + identifier + "/feed", query));
        }
Esempio n. 2
0
        /// <summary>
        /// Posts a status message to the wall of specified <var>identifier</var>.
        /// </summary>
        /// <param name="identifier">The identifier of the user, page or similar.</param>
        /// <param name="message">The text of the status message.</param>
        public string PostStatusMessage(string identifier, string message)
        {
            // Construct the query string
            NameValueCollection query = new NameValueCollection {
                { "message", message },
                { "access_token", Client.AccessToken }
            };

            // Make the call to the API
            return(SocialUtils.DoHttpPostRequestAndGetBodyAsString("https://graph.facebook.com/" + identifier + "/feed", query));
        }
        public InstagramAccessTokenResponse GetAccessTokenFromAuthCode(string authCode)
        {
            // Initialize collection with POST data
            NameValueCollection parameters = new NameValueCollection {
                { "client_id", ClientId },
                { "client_secret", ClientSecret },
                { "grant_type", "authorization_code" },
                { "redirect_uri", RedirectUri },
                { "code", authCode }
            };

            // Make the call to the API
            string contents = SocialUtils.DoHttpPostRequestAndGetBodyAsString("https://api.instagram.com/oauth/access_token", null, parameters);

            // Parse the response
            return(InstagramAccessTokenResponse.ParseJson(contents));
        }
Esempio n. 4
0
        /// <summary>
        /// Exchanges the specified authorization code for a user access token.
        /// </summary>
        /// <param name="authCode">The authorization code received from the GitHub OAuth dialog.</param>
        public string GetAccessTokenFromAuthCode(string authCode)
        {
            NameValueCollection parameters = new NameValueCollection {
                { "client_id", ClientId },
                { "client_secret", ClientSecret },
                { "code", authCode }
            };

            // Add the redirect URI (if specified)
            if (!String.IsNullOrWhiteSpace(RedirectUri))
            {
                parameters.Add("redirect_uri", RedirectUri);
            }

            // Get the response from the server
            string contents = SocialUtils.DoHttpPostRequestAndGetBodyAsString("https://github.com/login/oauth/access_token", null, parameters);

            // Parse the contents
            NameValueCollection response = HttpUtility.ParseQueryString(contents);

            // Return the access token
            return(response["access_token"]);
        }