[RAILS] [Twitter API] Countermeasures when "It is not safe" appears on the https site

Introduction

This article is not a business, but something I noticed when developing a hobby app. If anyone knows of a better solution, please let me know.

[11/4 added] I wrote how to solve it on the back side. https://qiita.com/yuki82511988/items/075508793119d90783b1 https://qiita.com/yuki82511988/items/62acd438e4420ec01be3

environment

Nuxt.js * Rails API (using gem twitter)

Thank you for reading the article with such an unclear title. When I was developing a hobby web application using TwitterAPI, I finished the development of Arakata and used cerbot to make the page https.

------ However, Chrome has told me that it is not safe. There was a warning on the console, so I looked at it (sorry I didn't copy it)

May be dangerous because the image path is http Something like that was written.

image···? When I was curious and investigated, the path of the image obtained from twitterAPI started from http: //! Apparently this was the problem. surprised.

Cause code

controller.rb


    client = Authorization.init
    @data = client.search("#hashtag", result_type: "recent").take(4).collect do |tweet|
      {
        "image": "#{tweet.user.profile_image_url}",

The url I got here was http. At this stage, it is not a character string, so you should originally write the conversion process on the back side, but this time I wrote the following code on the front side to solve it.

counter-measure

front.vue


  response.data.tweet.forEach(
    (element) => {
      console.log(element.image)
      const str = element.image
      const replaced = str.replace('http', 'https');
      element.image = replaced;
      }

There is a better way, and I just changed the character string, so I felt like "Eh ...", but now the image is displayed and the warning disappears.

Summary

I took this method because the image did not disappear when I changed the http part to https with the verification tool, but was it really good? .. .. I solved it in a hurry, but if anyone knows a better way, please let me know.

Recommended Posts

[Twitter API] Countermeasures when "It is not safe" appears on the https site
When the project is not displayed in eclipse
[Ruby on rails] When executing the heroku command, bash: heroku: command not found is displayed. [Rails tutorial]
When changing user information using devise Settings on the edit screen when the password is not saved
The idea of cutting off when the error is not resolved
[Rails] When the layout change of devise is not reflected
Logback log is not output when the server application is closed
When the docker image created on Raspberry pi is read by docker on windows, the error "exec format error" appears.
[Rails] How to convert the URI of the image sent by http to https when using Twitter API
What to do when javax.el.ELException: Not a Valid Method Expression: appears when the JSF screen is displayed