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
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.
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.
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.
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