teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

コードの修正

2020/08/23 09:24

投稿

yoshi448
yoshi448

スコア17

answer CHANGED
@@ -23,7 +23,7 @@
23
23
  this.combine[1]=this.id
24
24
  }else{
25
25
  if(this.id==0){
26
- this.combine[0]=this.tags
26
+ this.combine[0]=this.exist
27
27
  this.combine[1]=this.tags
28
28
  }
29
29
 

2

コードの修正

2020/08/23 09:23

投稿

yoshi448
yoshi448

スコア17

answer CHANGED
@@ -8,21 +8,29 @@
8
8
 
9
9
  ```gas
10
10
  function check_tag(tag){
11
- var url = "https://yourURL/wp-json/wp/v2/tags";
11
+ var url = "https://news.traicy.com/wp-json/wp/v2/tags";
12
12
  this.tags = UrlFetchApp.fetch(url);
13
- tags = JSON.parse(tags.getContentText());
14
- this.is_exist = false;
13
+ this.exist=false
15
14
  this.tag = tag
15
+ this.id = 0;
16
+ this.combine = [];
17
+ var tags = JSON.parse(this.tags.getContentText());
16
18
  tags.forEach(function(key){
17
- var tag_name = key["name"]
19
+ if(this.tag==key["name"]){
18
- if(tag_name==this.tag){
20
+ this.id = key["id"];
19
- this.is_exist=true;
21
+ this.exist = true;
20
- return this.is_exist,key["id"]
22
+ this.combine[0]=this.exist
23
+ this.combine[1]=this.id
21
- }else{
24
+ }else{
25
+ if(this.id==0){
22
- return this.is_exist,this.tags
26
+ this.combine[0]=this.tags
27
+ this.combine[1]=this.tags
23
- }
28
+ }
29
+
30
+ }
31
+
24
32
  })
25
-
33
+ return this.combine
26
34
  }
27
35
 
28
36
  function post_tag(name){

1

文章の改善

2020/08/23 06:57

投稿

yoshi448
yoshi448

スコア17

answer CHANGED
@@ -1,7 +1,9 @@
1
1
  調べても出てこなかったので自分で作りました。
2
2
  あまりgasを使わないのと突貫工事だったこともあり、かなりコードがきたないですがこんな感じです。
3
+ 文字列を付与するというよりもタグを全て取得して、タグが存在しているのならそのidを、ないなら新しく登録して登録したタグのidを使う感じにしました。
4
+ slackの3秒ルールに引っかかる場合は全てのタグをどこかに保存してそれを読み込むとかすればいいかもですね〜(今回は元から3秒超えてたので無視しました)
5
+
3
6
  正直thisとかよくわからないのであってるかどうか…笑
4
- スコープのあれこれなんですかね?
5
7
  まあとりあえずこれで動いたので自己解決しました!
6
8
 
7
9
  ```gas