[Java] The story of a student who was spared by the trend of SARS-CoV-2 and finally made a Twitter App that the limit of Twitter API was lost

14 minute read

Introduction

When you run into a problem, everyone googles, right? This time, I was googled even when I was restricted by API, but the amount of Japanese information that appears is very small. .. ..

So I decided to write this article in hopes of helping someone who has fallen into the same situation as me. (** It’s a shame ) ( Even though I want to write, there are quite a few **) (In other words, there are so many talks that need not be done **)

This story is a record for everyone to carry out “** Attack the ball with stones of other mountains **”. I pray that I won’t take the same rut as I do. .. ..

(If you only need to know how to remove the limitation of Twitter API **, it is enough to read only Summary)

March 2020

A new coronavirus called SARS-CoV-2 has become popular. I hope that the person reading this is saying “I have never had that kind of thing”… Due to the virus, schools across the country have closed their schools.

As a result, I was a second year high school student (third year high school student in 2020), but I could not go to school. My school did not pose any problems, even though it was a self-proclaimed primary school, and took the stance of “do your best in self-study.”

April 2020

On February 27 (Is it right?) Prime Minister Abe continued to close the school even after it started in April in order to further extend the period when he requested that the schools all over the country be closed. As expected, my school also mailed the assignments to me, which became the form of “home study.”

April 14, 2020 Midnight-April 15, Dawn

Immediately before entering this school holiday, some were told that they were sour that their mouths were sour, and that their ears hurt.

“** If you’re a student at this school, look at Classi and the school’s website everyday!**”

(Aside from: Concentration of access due to this turmoil and Unauthorized accesscombodroppedthereputationofstudentsforClassi)

Of course, I am also a student of “this school”, so I read these two many times every day. But,

**…Yup. It’s a pain. **

Then, just before dawn (around 1:00) on the 15th, **Let’s create a service that monitors the school’s HP and notifies you when it is updated! I decided to **.

April 15, 2020 morning

I started to take this idea into shape.

“Is it Java after all?” (← Only Java can be used) “Use Gradle” (← I’m not sure about Gradle but it’s useful) “If it is updated so that everyone can see it, it will flow to Twitter” (← important here **)

While thinking about various things, (according to my uncertain memory), I finished making it quickly in about an hour. The specifications are like this↓

・Assuming constant operation on Raspberry Pi
・Access the school website every few minutes
・Compare with previously acquired data and tweet if there is any change

I used Twitter4J-4.0.7 to hit the Twitter API.

After that, we performed a test operation using the news section of Yahoo! JAPAN, confirmed that updates were detected normally, and we could tweet.

April 15, 2020 around 10:00

We have not moved to the Raspberry Pi yet, and we have started trial operation with a MacBook for development targeting school HP. The school’s website is updated so slowly that it is incomparable to Yahoo! JAPAN (or even the news section), so I left it in this state for a while.

At this point, the bot’s account was locked and only me and my good friend A could see it.

April 15, 2020 15:16

I posted a tweet, “I’m a little worried whether it will be Librahack()”, in the rear. After all, there was no problem.

April 15, 2020 17:34

** School HP has been updated! !! !! ** Yes, I finally got the operation check! !! You can tweet normally! !! I made a guts pose with all my might.

April 15, 2020 19:00

(** I forgot what I did **) Apparently I did some maintenance in the past. Along with that, we added a playful function to say hello in the morning and at night.

I and friend A both turned on the notification of Bot dirt so that I could notice the bot’s tweet immediately, but I forgot to turn it off even though friend A cut the notification for maintenance. It was with bonus () Thanks to you, a lot of notifications for test tweets during maintenance…

April 15, 2020 21:40

After completing the maintenance, I unlocked the bot and unlocked it all over the world. When I advertised it with my friend A, many people immediately followed. Someone said that he was “competent”. (I was so happy)

Date unknown

I’ve forgotten the exact date and time, but I’ve probably added the ability to DM the error content to my Twitter account if a bot got an error around. (PolicyIt’sastorythatyoucanreaditproperly.Iwanttotellmypast.)

April 16, 2020 16:30

The school HP has undergone maintenance and is temporarily disconnected. I didn’t know what I was doing…

The bot threw an UnknownHostException and knew the error when DM came. Until this time, I was wondering, “This function is Eyan!” (** I want to hit **)

Since HP was informed in advance that the maintenance would be done, I decided to leave it as “If you wait a while, I’ll fix it”.

April 16, 2020 16:45

I was a little worried because I was continually emitting errors intermittently, so I stopped the bot.

April 16, 2020 16:52

I restarted the bot and confirmed that it could connect to HP normally. I wonder why they didn’t connect…

April 16, 2020 17:06

Finally the fateful time has come. I was worried that it was working properly, so I found the bot restarting at 16:52 and looking at the log frequently.

**that? I got an error about Twitter4J…? **

403:The request is understood, but it has been refused.An accompanying error message will explain why.This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about -twitter-limits-update-api-dm-and-following).
message-Application cannot perform write actions.Contact Twitter Platform Operations through https://support.twitter.com/forms/platform
code-261

Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=796590e6 or
http://www.google.co.jp/search?q=802fbd73
TwitterException{exceptionCode=[796590e6-802fbd73], statusCode=403, message=Application cannot perform write actions.Contact Twitter Platform Operations through https://support.twitter.com/forms/platform, code=261, retryAfter=-1, rateLimitStatus=null, version=4.0.7}
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:170)
at twitter4j.HttpClientBase.request(HttpClientBase.java:57)
at twitter4j.HttpClientBase.post(HttpClientBase.java:86)
at twitter4j.TwitterImpl.post(TwitterImpl.java:2138)
at twitter4j.TwitterImpl.sendDirectMessage(TwitterImpl.java:577)
at twitter4j.TwitterImpl.sendDirectMessage(TwitterImpl.java:611)
at twitter4j.TwitterImpl.sendDirectMessage(TwitterImpl.java:616)

Apparently it’s ridiculous when tweeting.

For the time being, I stopped the bot, and I was really impatient, thinking “** But I was able to tweet normally up to now …? **” For the time being Apps page of Twitter Developers has been accessed.

200419-0001.png

RESTRICTED TO API READ ACCESS ONLY (Translation: Your app has limited writing, you can read it.)

I’m even more impatient. Of course googled.

screencapture-google-search-2020-04-20-13_17_35.pngThere are only three Japanese-style pages. I’m even more impatient.

For the time being, access How to unfreeze the application on Twitter | Net Goodwill Service.

Apparently, you can contact us from Twitter API Policy Support.

screencapture-help-twitter-forms-platform-2020-04-20-13_24_41.png

In the “Details” section, I also filled in and sent other necessary information as follows (It is an image of a strange memory).

This app is a bot that monitors specific websites and tweets when they are updated. When an error occurred, I implemented a function to send the content of the error to another account I own with DM, but since a large number of errors occurred, it was judged that a large amount of DM was sent and the function was I think it was restricted. In order to prevent this from happening in the future, we will take measures to increase the interval for sending DM, so please remove the restriction.

Yes. I sent a message that I was regretful because I was very confused about the reason for being restricted.

Directly go to the mail folder as it is.

**…Hasn’t anything come? **

I didn’t even receive an automatic reply email. If you go back to the Net Zougen-san’s page,

  • It may be unfrozen within a few hours of applying, or after a few days, it may be unfrozen, and additional questions may be asked.

In my case, it was accidentally frozen three times, but it was canceled 5 hours after applying.

**Hmm. Well, the people on Twitter also work from home. I was convinced, and decided to wait leisurely.

April 16, 2020 20:00

**I can’t tweet, but run locally for yourself! I thought it was ** and tried to start it,

**Bot “UnknownHostException”

I just lost the limit, but I can’t connect to the school website. This is a crying bee.

Try to access it with Chrome on MacBook. You can see… Connect to the Raspberry Pi with ssh and ping the school HP. …Unknown host. Ping on your MacBook. …Unknown host.

Where in my head? ? ? have become. Why can’t I see and ping in Chrome?

**…Maybe browser cache? **

Flashes and deletes all Chrome caches → Access in secret mode.

200420-0002.png

DNS_PROBE_FINISHED_NXDOMAIN…? ? Apparently something happened when resolving names with DNS.

〜Time spent investigating various things through trial and error〜

…solved. Apparently, something happened around the DNS due to the maintenance that entered the school HP around 16:30 on April 16th, and the DNS cache of the router (of which 192.168.11.1) was out of date. If you use Google Public DNS (8.8.8.8), you can connect normally.

(I’m sorry to deviate from the main subject)

April 17, 2020 0:20

I’m using a MacBook with an ssh client, but I can’t connect to MacBook-Raspberry Pi.

Here is my tweet at this time.

to make matters worse, a swastika that is no longer connected to mackerel

It’s weird to have two bees in the middle of the night and crying, but don’t worry.

Since the network side is sparse, I got out of the ** riot ** of turning off the power of Raspberry Pi & reinstalling Raspbian. (It’s a nice thing about Raspberry Pi that you can do this easily.)

April 17, 2020 17:00

Also, since the MacBook-Raspberry Pi part died, I was again on breach.

By the way, after cleaning up DNS issues on April 16th, Move the bot locally → Post it to Twitter manually if it detects an update by looking at the log I continued to operate with that feeling.

One day has passed since I applied for the restriction removal, but I have not received a single email let alone the restriction removal. **

April 19, 2020 0:13

After 2 days from the application, there was no sound, and I felt nervous. I decided to make an inquiry from Twitter API policy support again.

**But in English. **

Remember when you signed up for Twitter Developer, it was written in English? Remembering that, **Maybe for developers, English only? .. I was worried about **, so I used my ability of Eiken 2nd grade, CEFR B1 ** ~ ~ (It is a lie DeepL I entered the details in English and sent.

I sent the same message in Japanese a few days ago, but I would like to send it in English as well, just in case.I apologize for the duplication. This app is a bot that monitors a specific website and tweets when it detects an update.I had implemented a function to send a DM to another account I own (@username) when an error occurs, but due to the large number of errors. , I think it was judged that this bot sent a large number of DMs and was restricted.To prevent this from happening in the future, I have removed that feature, so please remove the restriction. Thank you.

Go straight to your mail folder.

Hello,

Thanks for reaching out. Your app has been restricted or suspended due to one or more violations of our Developer Agreement and Policy,AutomationRules,DisplayRequirementsand/orTwitterRules. Common reasons for this happening include:

・Users reporting content posted through your app as spam (Tweets, RTs, favs, DMs, etc.) ・Abusive use of automations, like auto-following/unfollowing ・Suspicious API usage, such as repeatedly hitting rate limits ・Display violations regarding how you must show Tweets

This list is not exhaustive, so review our policy documentation to ensure that your app and your app’s users are following all of our rules.

Please respond to this email if you need further clarification, but note that we will only consider a request to lift this restriction after you provide us with the following information:

App ID and consumer key ・Link to and instructions on how to log into your app to review it for compliance ・A list of specific changes that you have made to resolve policy non-compliance

We will not respond to requests to lift restrictions that do not include this information.

Regards,

Twitter Platform Operations

**I got an automatic reply! !! !! !! **

At this point I’m pretty excited. At a level where the grin does not stop. ** However, I don’t know what Twitter is saying, so I will **super-translate.

Thank you for contacting me. Your app violated some rule, so I restricted it. It seems that it is often restricted at such times.

When somebody reports this app as spam・When you abuse automation such as automatically following or unfollowing ・When you hit the API limit many times ・When you violate the rules for showing tweets on your website

The reason for the limitation is not the only one. Think hard about what you did.

If you have any questions, don’t reply to this email. But we won’t lift the limit unless you give us this information.

App ID and consumer key ・How to log in to the application ・What was changed so as not to be restricted

Please be aware that we do not reply to emails such as “Please remove restrictions ~ ~” that do not include them.

From a person on Twitter

**…I’m glad I wrote so much in the “Details” section! !! **

That’s why I will send almost everything written in the details column by e-mail. (I copied and saved what I wrote just in case)

Hello.I’m Japanese, so I’m not good at English.I apologize for it.

App ID and consumer key App ID: Consumer Key:

・Link to and instructions on how to log into your app to review it for compliance This app has no website.It just tweets. My profile is:

A list of specific changes that you have made to resolve policy non-compliance I had implemented a function to send a DM to another account I own (@username) when an error occurs, but due to the large number of errors, I think it was judged that this bot sent a large number of DMs and was restricted To prevent this from happening in the future, I have removed that feature.

Sincerely,

…Huh.

April 19, 2020 14:10

Ever Move the bot locally → Post it to Twitter manually if it detects an update by looking at the log I continued to operate with that feeling, but it is hard to see the log diligently.

So, I decided to run it as a Discord Bot until the write restriction was lifted.

I used JDA-4.0.0_39 to hit Discord’s API, and the implementation was completed in a few hours.

April 21, 2020 12:00

Up to this point, it is compatible with Twitter (still limited) and Discord, but for some reason I also wanted to support LINE. I searched for a bit and found LINE Messaging API SDK for Java, so I implemented it in about an hour.

By the way, the reply from Twitter has not come yet.

June 4, 2020 7:50

Yes, about a month and a half after I responded to the email, I finally received a reply from Twitter this morning.

Hello @username,

Thank you for reaching out.We have reviewed your request and have reactivated your API key.Going forward, carefully ensure that your application adheres to Twitter’s policies:

Developer Agreement and Policy

Automation Rules

Twitter Rules

Please note, applications found to be violating policy again may be subject to permanent suspension.

Regards,

Twitter Platform Operations

↓ I will translate it.

@ User name, Chiss.

Thank you for contacting us. I read everything you said and tried to get rid of API restrictions. What you want to follow this rule properly, and what are you doing.

Developer Agreement and Policy

Automation Rules

Twitter Rules

If you violate the policy in the future, please be aware that you may be able to use this account forever.

Then.

Twitter Platform Operations

** Yoshhhhh! !! ** This ↓ that was displayed on the Twitter Developers Apps page was also gone.

200419-0001.png

After that, I changed the settings so that the bot would tweet, and I was able to confirm that I could tweet firmly. Thus, the My VS Twitter battle ended. .. ..

Summary

What to do when you are restricted by the Twitter API

screencapture-help-twitter-forms-platform-2020-04-20-13_24_41.png

  • Check if there is an automatic reply, then interact with people on Twitter. **In English. **
  • ** Wait if you haven’t come. Just wait. **

Other lessons

・Read the policy properly **・Do not use the DM function unless otherwise **・The world of programmers should have the recognition that basic English is **

Thank you page

How to remove the application freeze on Twitter | Net Goodwill Service