예제 #1
0
        /// <summary>
        /// Modify the relationship between the current user and the target user.
        /// Required scope: relationships.
        /// </summary>
        /// <param name="relationshipAction">One of follow/unfollow/block/unblock/approve/deny.</param>
        public async Task <string> PostRelationshipActionAsync(long userId, RelationshipActions relationshipAction)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                var response = await httpClient.PostAsync(RelationshipEndpointUrlsFactory.CreatePOSTRelationshipActionUrl(userId, this.accessToken, relationshipAction), null);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    return(responseContent);
                }
                else
                {
                    throw new InstagramAPIException(responseContent);
                }
            }
        }
예제 #2
0
        private static string BuildPOSTRelationshipActionUrlQueryString(string accessToken, RelationshipActions relationshipAction)
        {
            var queryString = HttpUtility.ParseQueryString("");

            queryString["access_token"] = accessToken;
            switch (relationshipAction)
            {
            case RelationshipActions.Follow:
                queryString["action"] = "follow";
                break;

            case RelationshipActions.Unfollow:
                queryString["action"] = "unfollow";
                break;

            case RelationshipActions.Block:
                queryString["action"] = "block";
                break;

            case RelationshipActions.Unblock:
                queryString["action"] = "unblock";
                break;

            case RelationshipActions.Approve:
                queryString["action"] = "approve";
                break;

            case RelationshipActions.Ignore:
                queryString["action"] = "ignore";
                break;
            }
            return(queryString.ToString());
        }
예제 #3
0
        public static string CreatePOSTRelationshipActionUrl(long userId, string accessToken, RelationshipActions relationshipAction)
        {
            var queryString = BuildPOSTRelationshipActionUrlQueryString(accessToken, relationshipAction);

            return(BuildRelationshipUrl(userId, InstagramAPIUrls.RelationshipsEndpointsUrl, queryString));
        }
예제 #4
0
        public static Uri CreatePOSTRelationshipActionUrl(long userId, string accessToken, RelationshipActions relationshipAction)
        {
            var queryString = BuildPOSTRelationshipActionUrlQueryString(accessToken, relationshipAction);

            return(new Uri(InstagramAPIUrls.BaseAPIUrl + string.Format(InstagramAPIEndpoints.RelationshipEndpoint, userId) + "?" + queryString));
        }
        /// <summary>
        /// Modify the relationship between the current user and the target user.
        /// Required scope: relationships.
        /// </summary>
        /// <param name="relationshipAction">One of follow/unfollow/block/unblock/approve/deny.</param>
        public async Task <string> PostRelationshipActionAsync(long userId, string accessToken, RelationshipActions relationshipAction)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                Uri uri = RelationshipEndpointUrlsFactory.CreatePOSTRelationshipActionUrl(userId, accessToken, relationshipAction);
                if (this.EnforceSignedRequests)
                {
                    uri = uri.AddParameter("sig", Utilities.GenerateSig(string.Format(InstagramAPIEndpoints.RelationshipEndpoint, userId), this.ClientSecret, uri.Query));
                }
                var response = await httpClient.PostAsync(uri, null);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    return(responseContent);
                }
                else
                {
                    throw new InstagramAPIException(responseContent);
                }
            }
        }