Beispiel #1
0
        /// <summary>
        /// Get information about a location
        /// http://instagram.com/developer/endpoints/locations/#get_locations
        /// </summary>
        /// <param name="name">The name of the location</param>
        /// <returns>ApiSingleReponse with a Location record on the data node.</returns>
        public ApiSingleResponse <Location> Locations(string name)
        {
            string json = GetJSON(string.Format(ApiUrls.LOCATIONS_URL, name, base._token), null);
            ApiSingleResponse <Location> response = json.Deserialize <ApiSingleResponse <Location> >();

            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// Add's the comment to the media item
        /// http://instagram.com/developer/endpoints/comments/#post_media_comments
        /// </summary>
        /// <param name="mediaId">The id of the media object to add the comment to</param>
        /// <param name="text">The text of the comment</param>
        /// <returns>An ApiResponse<Comment> item object with a list of Comments the data node.</returns>
        public ApiSingleResponse <Comment> Comment(string mediaId, string text)
        {
            string json = GetJSON(string.Format(ApiUrls.COMMENTS_ADD_URL, mediaId, base._token, text), string.Format("text={0}", text), "POST");
            ApiSingleResponse <Comment> response = json.Deserialize <ApiSingleResponse <Comment> >();

            return(response);
        }
Beispiel #3
0
        /// <summary>
        /// Get the details (full record) of the specified media
        /// http://instagram.com/developer/endpoints/media/#get_media
        /// </summary>
        /// <param name="mediaId">The id of the media object to get the details for</param>
        /// <returns>An ApiSingleResponse<FeedItem> item object with single FeedItem on data node.</returns>
        public ApiSingleResponse <FeedItem> Media(string mediaId)
        {
            string json = GetJSON(string.Format(ApiUrls.MEDIA_URL, mediaId, base._token), null);
            ApiSingleResponse <FeedItem> response = json.Deserialize <ApiSingleResponse <FeedItem> >();

            return(response);
        }
Beispiel #4
0
        /// <summary>
        /// Remove a like on the media by the currently authenticated user
        /// http://instagram.com/developer/endpoints/likes/#delete_media_likes
        /// </summary>
        /// <param name="mediaId">The id of the media to remove the like from</param>
        /// <returns>ApiSingleResponse<string> containing a meta node (with http status) and a null data node</returns>
        public ApiSingleResponse <string> UnLike(string mediaId)
        {
            string json = GetJSON(string.Format(ApiUrls.LIKES_URL, mediaId, base._token), null, "DELETE");
            ApiSingleResponse <string> response = json.Deserialize <ApiSingleResponse <string> >();

            return(response);
        }
Beispiel #5
0
        /// <summary>
        /// Removes the specified comment from the media
        /// http://instagram.com/developer/endpoints/comments/#delete_media_comments
        /// </summary>
        /// <param name="mediaId">The id of the media to remove the comment from</param>
        /// <param name="commentId">The id of the comment to rememove</param>
        /// <returns>ApiSingleResponse<string> containing a meta node (with http status) and a null data node</returns>
        public ApiSingleResponse <string> UnComment(string mediaId, string commentId)
        {
            string json = GetJSON(string.Format(ApiUrls.COMMENTS_DELETE_URL, mediaId, commentId, base._token), null, "DELETE");
            ApiSingleResponse <string> response = json.Deserialize <ApiSingleResponse <string> >();

            return(response);
        }
Beispiel #6
0
        /// <summary>
        /// Get information about a tag
        /// http://instagram.com/developer/endpoints/tags/#get_tags
        /// </summary>
        /// <param name="name">The tag to lookup</param>
        /// <returns>An ApiSingleResponse with a single Tag object on the data node</returns>
        public ApiSingleResponse <Tag> Tag(string name)
        {
            string json = GetJSON(string.Format(ApiUrls.TAGS_URL, name, base._token), null);
            ApiSingleResponse <Tag> response = json.Deserialize <ApiSingleResponse <Tag> >();

            return(response);
        }
Beispiel #7
0
        public JsonResult Delete(FeedItem feedItem)
        {
            try {
                MediaClient client = new MediaClient(base.userToken.access_token);
                ApiSingleResponse <string> response = client.UnLike(feedItem.id);

                return(Json(new { success = true }));
            } catch { return(Json(new { success = false })); }
        }
        public JsonResult Create(PhotoComment comment)
        {
            try {
                MediaClient client = new MediaClient(base.userToken.access_token);
                ApiSingleResponse <Comment> response = client.Comment(comment.id, Server.UrlEncode(comment.text));

                return(Json(new { success = true }));
            } catch { return(Json(new { success = false })); }
        }
        //
        // GET: /Comment/Details/5

        public ActionResult Details(int id)
        {
            MediaClient client = new MediaClient(base.userToken.access_token);
            ApiSingleResponse <FeedItem> media = client.Media(id.ToString());

            ViewData["PhotoDetails"] = media.data;

            return(PartialView("PhotoDetails", media.data));
        }
Beispiel #10
0
        private void ConfigJwtAuthentication(IServiceCollection services)
        {
            var symmetricKey = Convert.FromBase64String(EncryptionUtil.ToBase64Encode("123456abcdefqwer"));

            services.AddAuthentication(x =>
            {
                x.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(symmetricKey),
                    ValidateIssuer           = false,
                    ValidateAudience         = false,
                    ValidateLifetime         = true,
                    ClockSkew = TimeSpan.Zero
                };

                x.Events = new JwtBearerEvents()
                {
                    OnAuthenticationFailed = async context =>
                    {
                        Console.WriteLine("ABCDDDDDDDDDDDDDDDDDDD");
                        var apiErrorMessage = new ApiErrorMessage();
                        var statusCode      = HttpStatusCode.Unauthorized;

                        if (context.Exception is SecurityTokenExpiredException)
                        {
                            apiErrorMessage.ErrorCode    = (int)ErrorCodeEnum.ACCESS_TOKEN_IS_EXPIRED;
                            apiErrorMessage.ErrorMessage = ErrorMessageConstant.ACCESS_TOKEN_IS_EXPIRED;
                        }
                        else
                        {
                            apiErrorMessage.ErrorCode    = (int)ErrorCodeEnum.ACCESS_TOKEN_IS_INVALID;
                            apiErrorMessage.ErrorMessage = ErrorMessageConstant.ACCESS_TOKEN_IS_INVALID;
                            statusCode = (HttpStatusCode.Forbidden);
                        }

                        var apiResponseException = new ApiResponseException()
                        {
                            ErrorMessages = new List <ApiErrorMessage>
                            {
                                apiErrorMessage
                            },
                            StatusCode = statusCode
                        };

                        var apiResponse = new ApiSingleResponse <string>()
                        {
                            Data   = null,
                            Errors = apiResponseException.ErrorMessages
                        };

                        context.Response.StatusCode  = (int)statusCode;
                        context.Response.ContentType = "application/json";
                        await context.Response.WriteAsync(JsonSerializer.Serialize(apiResponse, new JsonSerializerOptions {
                            PropertyNamingPolicy = JsonNamingPolicy.CamelCase
                        }));
                    }
                };
            });
        }