m_azami
m_azami

Reputation: 23

Instagram api response with empty data array in asp.net

I’m trying to access to Media use hashtag from the Instagram API using their authenticated access token.returns empty data. I’m using this URL: https://api.instagram.com/v1/media/{tag name}?access_token={verified access token} and this is the result I’m receiving: {"pagination": {}, "meta": {"code": 200}, "data": []} Because it has a 200 return code, the access token is valid. So why don’t I see any liked posts? i added another user in sandbox users but so returns empty data. What to do? please help me!

[my C# code]

 static string code = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(Request["code"]) && !Page.IsPostBack)
        {
            code = Request["code"];
            GetDataInstagramToken();
        }
    }
    public void GetDataInstagramToken()
    {
        var json = "";
        try
        {
            NameValueCollection parameters = new NameValueCollection();
            parameters.Add("client_id", ConfigurationManager.AppSettings["client_id"]);
            parameters.Add("client_secret", ConfigurationManager.AppSettings["client_secret"]);
            parameters.Add("grant_type", "authorization_code");
            parameters.Add("redirect_uri", ConfigurationManager.AppSettings["redirect_uri"]);
            parameters.Add("code", code);
            WebClient client = new WebClient();
            var result = client.UploadValues("https://api.instagram.com/oauth/access_token", "POST", parameters);
            var response = System.Text.Encoding.Default.GetString(result);
            var jsResult = (JObject)JsonConvert.DeserializeObject(response);
            string accessToken = (string)jsResult["access_token"];
            Int64 id = Convert.ToInt64(jsResult["user"]["id"]);
            var clientid = ConfigurationManager.AppSettings["client_id"];
    Page.ClientScript.RegisterStartupScript(this.GetType(), "GetToken", "<script>var ClientId=\"" + @"" + clientid + "" + "\";var instagramaccessid=\"" + @"" + id + "" + "\"; var instagramaccesstoken=\"" + @"" + accessToken + "" + "\";</script>");

        }

        catch (Exception ex)
        {

            throw;
        }

my js code function GetSearchMedia() {

        var seachText = document.getElementById('Search').value;

        $.ajax({
            type: "GET",

            async: true,

            contentType: "application/json; charset=utf-8",

            url: 'https://api.instagram.com/v1/tags/' + seachText + '/media/recent?access_token=' + instagramaccesstoken,

            dataType: "jsonp",

            cache: false,

            beforeSend: function () {

                $("#loading").show();

            },

            success: function (data) {
                debugger
                for (var i = 0; i < data["data"].length; i++) {

                    $("#ImageUL").append("<li><img src=" + data.data[i].images.standard_resolution.url + "></li>");

                }
            }

        });
    }


</script>

Upvotes: 2

Views: 429

Answers (1)

krisrak
krisrak

Reputation: 12952

You will only see your and your sandbox users post in API response if they have posted a photo with the hashtag your are looking up using API.

So if you add a photo to instagram with an hashtag and then make API call for that hashtag, you will then see your post in API response <- try this

Upvotes: 0

Related Questions