Search code examples
c#instagram-api

Following an Instagram id return 404 in c#


I'm trying to follow a user-id in Instagram using the codes below, but it always return 404 error.My app is not in sandbox mode

        public void doFollow(string userid)
    {
        NameValueCollection parameters = new NameValueCollection();
        parameters.Add("access_token", ACCESS_TOKEN);
        WebClient client = new WebClient();
        string url = "https://api.instagram.com/v1/users/" + userid + "/follow";
        //404 error happens in the next line
        var result = client.UploadValues(url, "POST",parameters);
        var response = System.Text.Encoding.Default.GetString(result);
        var jsResult = (JObject)JsonConvert.DeserializeObject(response);
        string incomStats = (string)jsResult["incoming_status"];
    }

Solution

  • According to the Instagram API documentation the endpoint is

    https://api.instagram.com/v1/users/{user-id}/relationship

    and you pass in a parameter of "ACTION=follow".

    https://www.instagram.com/developer/endpoints/relationships/#post_relationship