Instagram更新后,Android Studio中无法通过?__a=1获取公开页JSON的求助
__a=1 Endpoint Access Denied Error Hey, I’ve run into similar headaches with Instagram’s public data endpoints after their updates, so here are some actionable solutions to try out:
Add Proper Request Headers
Instagram now blocks requests that don’t look like they’re coming from a legitimate browser. You need to set at least a validUser-Agentheader in your AsyncHttpClient call to bypass basic anti-scraping checks. Here’s how to tweak your code:AsyncHttpClient client = new AsyncHttpClient(); client.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"); client.addHeader("Accept-Language", "en-US,en;q=0.9"); client.get("https://www.instagram.com/nasa/?__a=1", new TextHttpResponseHandler() { // Your response handling logic here });Switch to the Updated Public Endpoint
Instagram has deprecated the old__a=1parameter in many cases. The current working endpoint for fetching public user profile data is:https://www.instagram.com/api/v1/users/web_profile_info/?username=nasaMake sure to include the same valid request headers as above when calling this endpoint. The response will be a JSON object with the user’s profile details, recent posts, and other public information.
Migrate to a Modern HTTP Library
AsyncHttpClient is no longer actively maintained, which can lead to compatibility issues with modern web security measures (like TLS versions or cookie handling). Switching to libraries like OkHttp or Retrofit gives you better control over requests and better support for current web standards. For example, an OkHttp implementation would look like this:OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://www.instagram.com/api/v1/users/web_profile_info/?username=nasa") .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36") .build(); client.newCall(request).enqueue(new Callback() { // Handle response here });Check for IP Restrictions
If you’ve made multiple repeated requests quickly, Instagram might have temporarily blocked your IP address. Test the request from a different network (like your mobile hotspot) to rule this out. If that works, add delays between requests or use a rotating proxy—just make sure to comply with Instagram’s terms of service when doing this.
Keep in mind that Instagram’s public endpoints can change without warning, so it’s worth checking if their official Graph API fits your needs (though it requires authentication for most use cases).
内容的提问来源于stack exchange,提问作者javip

