spencerwooo / substats

( `д′) how many followers do i have? how many!
https://substats.swo.moe
MIT License
813 stars 56 forks source link

instagram queries always returns 0 followers #19

Closed SaoYan closed 3 years ago

SaoYan commented 3 years ago
https://api.spencerwoo.com/substats/?source=instagram&queryKey=spencer_wooo

Result:

{
  "status": 200,
  "data": {
    "totalSubs": 0,
    "subsInEachSource": {
      "instagram": 0
    },
    "failedSources": {
      "substats-error": {}
    }
  }
}

I tried with my ins id and some others, the API always returns 0 followers. The handler code for instagram looks fine. Maybe there's something wrong with the backend. @spencerwooo

SaoYan commented 3 years ago

I found the problem: calling fetch() on endpoint https://www.instagram.com/${username}/?__a=1 returns HTML rather than JSON. It seems that https://www.instagram.com/${username}/?__a=1 is not a valid ins GraphQL API. In order to use ins API, an ins business account and a Facebook developer account is required.

You need to create an app under the Facebook dev account and get it reviewed. An access token will be granted to the APP, which can be used to invoke the Graph API. The endpoint is https://graph.facebook.com/v3.2/<account_id>?fields=followers_count&access_token=<token>

For more details see https://developers.facebook.com/docs/instagram-api/getting-started

This is probably out of this project's scope... So you may want to remove the current support for Instagram

spencerwooo commented 3 years ago

Hmmmm, this worked before, let me have a look.

spencerwooo commented 3 years ago

@SaoYan Could you try to deploy a second "Substats" on your Cloudflare Workers account and try if the Instagram path works? It seems that the current api.spencerwoo.com is limited by Instagram, because I can request the correct parameters through this (undocumented) API locally.. (Though I'm not sure.)

image

SaoYan commented 3 years ago

https://www.instagram.com/${username}/?__a=1 is not supposed to be used, so I guess any domain that invokes it for some times will be banned.

spencerwooo commented 3 years ago

So the rightful way to do this would be to get a verified dev account from instagram, and in order to do so I'm going to need a business account... All right I give up, dropping instagram support for now.

spencerwooo commented 3 years ago

This is weird, I rebuilt and published a version to Cloudflare Workers and the route is working again.

image

Can you confirm @SaoYan? If so, I'm going to mark this route as unstable instead of inaccessible.

spencerwooo commented 3 years ago

Nope, never mind, still banned.