instagram ?__a=1 not working in Mobile but when we hit the api in browser and postmen its working fine

Viewed 615

It's stopped working for the last 5 days before that it's working fine.

now when we call this end point in mobile then return 429 and redirect to the Instagram login page.

1 Answers

I had the same problem and I've fixed it by changing the User-Agent to Mozilla/5.0 in the request's header.

Here is what I did on iOS (Swift):

let url = URL(string: "https://www.instagram.com/spacex/?__a=1")
let request = NSMutableURLRequest(url: url)
request.setValue("Mozilla/5.0", forHTTPHeaderField: "User-Agent")
request.setValue("no-cache", forHTTPHeaderField: "Cache-Control")
request.httpMethod = "GET"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
let session = URLSession.shared

DispatchQueue.global(qos: .background).async {
  let requestData = session.dataTask(with: request as URLRequest) { (data, response, error) -> Void in
    if let error = error {
      print("Error @ loadInstagram(): \(String(describing: error))")
      return
    }
    
    if let data = data {
      self.processInstagram(data: data) // function for processing the json data received
    } else {
      print("Error - missing data @ loadInstagram()")
    }
  }
  requestData.resume()
}
Related