Get Twitter Follow Count Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Get Twitter Follow Count

Post by armin889 » 28 Nov 2021, 01:37

Hi
is there a way in AHK to get the Twitter Follow Count of a user and put it in a variable
thanks a lot

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Get Twitter Follow Count

Post by mikeyww » 28 Nov 2021, 08:06

Code: Select all

MsgBox, 64, CNN Followers, % followers := twitterFollowers("cnnbrk")

twitterFollowers(screenName) { ; https://www.autohotkey.com/boards/viewtopic.php?p=431740#p431740
 Static url := "https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names="
 Try whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
 Catch
  Return
 whr.SetTimeouts(0, 30000, 30000, 600000), whr.Open("GET", url StrReplace(screenName, "@"), False)
 Try {
  whr.Send()
  Sleep, 100
  RegExMatch(whr.ResponseText, """followers_count"":\K\d+", followers)
 }
 Return followers
}

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: Get Twitter Follow Count

Post by armin889 » 28 Nov 2021, 21:10

thx @mikeyww this script looks nice
bot for me it not work i just get this
Attachments
notepad++_VcsE7gmDy8.jpg
notepad++_VcsE7gmDy8.jpg (3.22 KiB) Viewed 1509 times

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Get Twitter Follow Count

Post by mikeyww » 28 Nov 2021, 22:19

I just ran this exact script and saw the following.

image211128-2218-001.png
Script output
image211128-2218-001.png (6.92 KiB) Viewed 1503 times

AHK version: 1.1.33.10

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: Get Twitter Follow Count

Post by armin889 » 30 Nov 2021, 05:16

i also have Version 1.1.30.01
hmmm?
any idea whats wrong?

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Get Twitter Follow Count

Post by mikeyww » 30 Nov 2021, 08:33

Sorry I do not know what issue you are having. I believe that Twitter has a v2 API available upon registration. That might enable you to do the same thing. I have not tested it.

If you remove the Try command itself, it may enable you to see an error message if there is one.

Code: Select all

MsgBox, 64, CNN Followers, % followers := twitterFollowers("cnnbrk")

twitterFollowers(screenName) { ; https://www.autohotkey.com/boards/viewtopic.php?p=431740#p431740
 Static url := "https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names="
 whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
 whr.SetTimeouts(0, 30000, 30000, 600000), whr.Open("GET", url StrReplace(screenName, "@"), False)
 whr.Send()
 Sleep, 100
 RegExMatch(whr.ResponseText, """followers_count"":\K\d+", followers)
 Return followers
}
You may also wish to see what happens if you paste the following URL into your Chrome browser.

https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=cnnbrk

At my end, this downloads a file called json.json. It contains content similar to the following.

[{"following":false,"id":"428333","screen_name":"cnnbrk","name":"CNN Breaking News","protected":false,"followers_count":61686905,"formatted_followers_count":"61.7M followers","age_gated":false}]

The script simply gets that text and reads the followers count from it.

If the Sleep, 100 is too short at your end, the process might fail, though I don't think it would. You could increase 100 to 500 or more, to see whether that makes a difference.

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: Get Twitter Follow Count

Post by armin889 » 30 Nov 2021, 23:18

Yes, if I paste the URL into the browser, then I get the file with the follow count

on the script I get an error now, check the pic in attached file

i also did higher sleep did not help

well, I compiled your script to .exe and tried it on my laptop and on a friend's PC , and there it works... so I guess there is some wrong setting in my windows
Attachments
AutoHotkey_jKMhKd06eM.jpg
AutoHotkey_jKMhKd06eM.jpg (29.28 KiB) Viewed 1349 times

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Get Twitter Follow Count

Post by boiler » 01 Dec 2021, 02:47

It could be your firewall settings that doesn’t allow for the Send() to occur.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Get Twitter Follow Count

Post by mikeyww » 01 Dec 2021, 06:15

I agree with boiler. Antivirus is sometimes an issue as well-- easy enough to disable it and test again. Finally, running as admin is also easy to try.

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: Get Twitter Follow Count

Post by armin889 » 01 Dec 2021, 06:22

I removed firewall and antivirus for test , also I do run as admin... still same
anyway I run it on my laptop now there it works fine

I have an additional question to your script: how I can read out the twitter name
my guess was like this, but not work, maybe u have an idea?

Code: Select all

twitterFollowers(screenName) { ; https://www.autohotkey.com/boards/viewtopic.php?p=431740#p431740
 Static url := "https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names="
 whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
 whr.SetTimeouts(0, 30000, 30000, 600000), whr.Open("GET", url StrReplace(screenName, "@"), False)
 whr.Send()
 Sleep, 3333
 RegExMatch(whr.ResponseText, """name"":\K\d+", followers)
 Return followers
}

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Get Twitter Follow Count  Topic is solved

Post by mikeyww » 01 Dec 2021, 06:50

Code: Select all

#Include d:\utils\JSON.ahk ; https://github.com/cocobelgica/AutoHotkey-JSON
tw := twitter("cnnbrk")
MsgBox, 64, Twitter results, % "Name     : " tw.name "`nFollowers: " tw.followers_count

twitter(screenName) { ; https://www.autohotkey.com/boards/viewtopic.php?p=431740#p431740
 Static url := "https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names="
 whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
 whr.SetTimeouts(0, 30000, 30000, 600000), whr.Open("GET", url StrReplace(screenName, "@"), False)
 whr.Send()
 Sleep, 100
 Return JSON.Load(whr.ResponseText).1
}
image211201-0646-001d.png
Output
image211201-0646-001d.png (21.86 KiB) Viewed 1216 times

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Get Twitter Follow Count

Post by boiler » 01 Dec 2021, 07:51

armin889 wrote: also I do run as admin... still same
This sounds like you are saying that your Windows user account has admin privileges (sorry, and ignore if not). That is not what is being suggested and does not matter. If you haven’t yet, try running the script itself as administrator by right-clicking on the script file in File Explorer and selecting “Run as administrator.” That causes the script to run as an “elevated process,” which doesn’t happen just because the user is an admin.


armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: Get Twitter Follow Count

Post by armin889 » 02 Dec 2021, 07:45

thanks this was very helpful
I installed the Easy fix from microsoft.com and this fixed the problem

armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

Re: Get Twitter Follow Count

Post by armin889 » 02 Dec 2021, 07:48

mikeyww wrote:
01 Dec 2021, 06:50

Code: Select all

#Include d:\utils\JSON.ahk ; https://github.com/cocobelgica/AutoHotkey-JSON
tw := twitter("cnnbrk")
MsgBox, 64, Twitter results, % "Name     : " tw.name "`nFollowers: " tw.followers_count

twitter(screenName) { ; https://www.autohotkey.com/boards/viewtopic.php?p=431740#p431740
 Static url := "https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names="
 whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
 whr.SetTimeouts(0, 30000, 30000, 600000), whr.Open("GET", url StrReplace(screenName, "@"), False)
 whr.Send()
 Sleep, 100
 Return JSON.Load(whr.ResponseText).1
}

image211201-0646-001d.png
great, thanks a lot for your time
do you know if there are more .json files on Twitter I can download, for example how much user an account Follow or how much like in Total

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Get Twitter Follow Count

Post by mikeyww » 02 Dec 2021, 10:20

I do not know.

Post Reply

Return to “Ask for Help (v1)”