質問編集履歴
5
補足欄を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -120,4 +120,78 @@
|
|
120
120
|
https://lets-emoji.com/black-circle-emoji/
|
121
121
|
|
122
122
|
### 補足
|
123
|
+
print("done") の代わりに、
|
124
|
+
print(res.msg.as_string()) や print(ascii(content))を入れた結果のログ:
|
125
|
+
|
126
|
+
```
|
127
|
+
{
|
128
|
+
insertId: "***"
|
129
|
+
logName: "projects/***/logs/cloudaudit.googleapis.com%2Factivity"
|
130
|
+
operation: {
|
131
|
+
first: true
|
132
|
+
id: "operations/***"
|
133
|
+
producer: "cloudfunctions.googleapis.com"
|
134
|
+
}
|
135
|
+
protoPayload: {
|
136
|
+
@type: "type.googleapis.com/google.cloud.audit.AuditLog"
|
137
|
+
authenticationInfo: {
|
138
|
+
principalEmail: "***@***"
|
139
|
+
}
|
140
|
+
authorizationInfo: [
|
123
|
-
|
141
|
+
0: {
|
142
|
+
granted: true
|
143
|
+
permission: "cloudfunctions.functions.update"
|
144
|
+
permissionType: "ADMIN_WRITE"
|
145
|
+
resource: "projects/***"
|
146
|
+
resourceAttributes: {
|
147
|
+
}}]
|
148
|
+
methodName: "google.cloud.functions.v1.CloudFunctionsService.UpdateFunction"
|
149
|
+
request: {
|
150
|
+
@type: "type.googleapis.com/google.cloud.functions.v1.UpdateFunctionRequest"
|
151
|
+
function: {
|
152
|
+
availableMemoryMb: 2048
|
153
|
+
dockerRegistry: "CONTAINER_REGISTRY"
|
154
|
+
entryPoint: "***"
|
155
|
+
eventTrigger: {
|
156
|
+
eventType: "google.pubsub.topic.publish"
|
157
|
+
resource: "projects/***"
|
158
|
+
}
|
159
|
+
ingressSettings: "ALLOW_INTERNAL_ONLY"
|
160
|
+
maxInstances: 1
|
161
|
+
name: "projects/***"
|
162
|
+
runtime: "python311"
|
163
|
+
serviceAccountEmail: "***@***"
|
164
|
+
sourceUploadUrl: "https://storage.googleapis.com/***"
|
165
|
+
timeout: "120s"
|
166
|
+
}
|
167
|
+
updateMask: "sourceUploadUrl"
|
168
|
+
}
|
169
|
+
requestMetadata: {
|
170
|
+
callerIp: "***"
|
171
|
+
callerSuppliedUserAgent: "***"
|
172
|
+
destinationAttributes: {
|
173
|
+
}
|
174
|
+
requestAttributes: {
|
175
|
+
auth: {
|
176
|
+
}
|
177
|
+
time: "2024-04-23T05:07:04.513356Z"
|
178
|
+
}}
|
179
|
+
resourceLocation: {
|
180
|
+
currentLocations: [
|
181
|
+
0: "***"
|
182
|
+
]}
|
183
|
+
resourceName: "projects/***"
|
184
|
+
serviceName: "cloudfunctions.googleapis.com"
|
185
|
+
}
|
186
|
+
receiveTimestamp: "2024-04-23T05:07:04.756380944Z"
|
187
|
+
resource: {
|
188
|
+
labels: {
|
189
|
+
function_name: "***"
|
190
|
+
project_id: "***"
|
191
|
+
region: "***"
|
192
|
+
}
|
193
|
+
type: "cloud_function"
|
194
|
+
}
|
195
|
+
severity: "NOTICE"
|
196
|
+
timestamp: "2024-04-23T05:07:03.340489Z"}
|
197
|
+
```
|
4
タイトルの変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
App Store Connect API から取得したデータ
|
1
|
+
App Store Connect API から取得したデータをBigQueryに格納できない
|
test
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
### 実現したいこと
|
2
2
|
[List All Customer Reviews for an App(アプリのすべての顧客レビューをリストする)](https://developer.apple.com/documentation/appstoreconnectapi/list_all_customer_reviews_for_an_app)
|
3
3
|
|
4
|
-
のデータを、BigQueryテーブルに格納したいが、エラーが出てしまう。
|
4
|
+
のデータを、BigQueryテーブルに格納したいが、エラーが出てしまうので解決したい。
|
5
|
-
特殊文字が含まれてることによる文字化けが原因だと考えている。下記2つを実現したい。
|
6
|
-
|
7
|
-
**① 特殊文字を削除したい。特殊文字全般を別の文字列に削除or置き換え、取り込まないようにしたい。
|
8
|
-
② 出力時に 'Content-Type': 'text/html; charset=utf-8' にしたい。**
|
9
5
|
|
10
6
|
### 発生している問題・分からないこと
|
7
|
+
|
8
|
+
特殊文字が含まれてることによる文字化けが原因かと仮定し、下記検証。
|
9
|
+
他原因は現状思いついていません。
|
11
10
|
|
12
11
|
**① 特殊文字を削除したい。**
|
13
12
|
→いろんな場所に .decode('utf-8','replace') を付与して試したが、意図した状態にならない。
|
3
書体の調整
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
のデータを、BigQueryテーブルに格納したいが、エラーが出てしまう。
|
5
5
|
特殊文字が含まれてることによる文字化けが原因だと考えている。下記2つを実現したい。
|
6
6
|
|
7
|
-
① 特殊文字を削除したい。特殊文字全般を別の文字列に削除or置き換え、取り込まないようにしたい。
|
7
|
+
**① 特殊文字を削除したい。特殊文字全般を別の文字列に削除or置き換え、取り込まないようにしたい。
|
8
|
-
② 出力時に 'Content-Type': 'text/html; charset=utf-8' にしたい。
|
8
|
+
② 出力時に 'Content-Type': 'text/html; charset=utf-8' にしたい。**
|
9
9
|
|
10
10
|
### 発生している問題・分からないこと
|
11
11
|
|
2
タイトルの変更、「実現したいこと」の加筆、「上記の詳細・結果」の変更、コードの追加
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
App Store Connect API から取得したデータ
|
1
|
+
App Store Connect API から取得したデータから特殊文字を削除できない / 出力時にContent-Typeを付与できない
|
test
CHANGED
@@ -1,16 +1,30 @@
|
|
1
1
|
### 実現したいこと
|
2
2
|
[List All Customer Reviews for an App(アプリのすべての顧客レビューをリストする)](https://developer.apple.com/documentation/appstoreconnectapi/list_all_customer_reviews_for_an_app)
|
3
3
|
|
4
|
-
のデータを、BigQueryテーブルに格納したい。
|
4
|
+
のデータを、BigQueryテーブルに格納したいが、エラーが出てしまう。
|
5
|
+
特殊文字が含まれてることによる文字化けが原因だと考えている。下記2つを実現したい。
|
6
|
+
|
7
|
+
① 特殊文字を削除したい。特殊文字全般を別の文字列に削除or置き換え、取り込まないようにしたい。
|
8
|
+
② 出力時に 'Content-Type': 'text/html; charset=utf-8' にしたい。
|
5
9
|
|
6
10
|
### 発生している問題・分からないこと
|
11
|
+
|
12
|
+
**① 特殊文字を削除したい。**
|
13
|
+
→いろんな場所に .decode('utf-8','replace') を付与して試したが、意図した状態にならない。
|
14
|
+
また、.decode('cp932','replace') に敢えて変換し特殊文字が消えることを期待したがこちらもうまくいかず。
|
15
|
+
|
16
|
+
**② 出力時に 'Content-Type': 'text/html; charset=utf-8' にしたい。**
|
17
|
+
→現状、バケットのファイルのページでContent-Type欄に
|
18
|
+
text/html; charset=utf-8
|
19
|
+
を手入力する必要がある。
|
20
|
+
|
21
|
+
※補足:
|
7
|
-
API
|
22
|
+
API経由でデータをバケットに格納すること自体は出来ている。
|
8
23
|
|
9
24
|
<実装状況>
|
10
25
|
Apple Developer API から連携
|
11
26
|
→ Google Cloud Function で読み込み
|
12
27
|
→ Google Cloud Storage に保存
|
13
|
-
└ Content-Type を "utf-8" に変更
|
14
28
|
→ Google BigQuery Studio でテーブルに書き出し ★読み込み不可
|
15
29
|
|
16
30
|
### エラーメッセージ
|
@@ -21,7 +35,77 @@
|
|
21
35
|
### 該当のソースコード
|
22
36
|
|
23
37
|
```
|
38
|
+
import base64
|
39
|
+
import logging, os, sys, re
|
40
|
+
import pprint
|
41
|
+
import datetime
|
42
|
+
import urllib.request,urllib.error
|
43
|
+
from google.cloud import storage
|
44
|
+
import jwt
|
45
|
+
import time
|
46
|
+
from google.cloud import secretmanager
|
47
|
+
from google.oauth2 import service_account
|
48
|
+
import json
|
49
|
+
|
50
|
+
# JWTトークンの生成
|
51
|
+
### 省略 ###
|
52
|
+
|
53
|
+
# APIからレポートを取得
|
54
|
+
def __get_reports(token,date_str=None):
|
55
|
+
base_url = 'https://api.appstoreconnect.apple.com/v1/apps/xxxxxxxx/customerReviews' #ダミー値
|
56
|
+
vendor_number = xxxxxxxx #ダミー値
|
57
|
+
|
58
|
+
if not date_str:
|
59
|
+
jst = datetime.timezone(datetime.timedelta(hours=+9), 'JST')
|
60
|
+
date_str = (datetime.datetime.now(jst) - datetime.timedelta(days=2)).strftime('%Y-%m-%d')
|
61
|
+
|
62
|
+
path_parameters = {
|
63
|
+
"id" : xxxxxxxx #ダミー値
|
64
|
+
}
|
65
|
+
|
66
|
+
query_parameters = {
|
67
|
+
}
|
68
|
+
|
69
|
+
url = base_url
|
70
|
+
|
71
|
+
headers = {'Authorization': 'Bearer ' + token,'Accept': '*/*'}
|
72
|
+
|
73
|
+
req = urllib.request.Request('{}?{}'.format(url, urllib.parse.urlencode(query_parameters)), headers=headers)
|
74
|
+
|
24
|
-
|
75
|
+
try:
|
76
|
+
with urllib.request.urlopen(req) as res:
|
77
|
+
content = res.read()
|
78
|
+
print("done") #デバッグ
|
79
|
+
code = 200
|
80
|
+
except (urllib.error.HTTPError, urllib.error.URLError) as e:
|
81
|
+
logging.error("Error occered in urllib.request.Request().\n code: " + str(e.code) + \
|
82
|
+
"\n reason: " + e.reason)
|
83
|
+
code = e.code
|
84
|
+
content = e.reason
|
85
|
+
print("error") #デバッグ
|
86
|
+
|
87
|
+
return (code, content, date_str)
|
88
|
+
|
89
|
+
# Cloud Storageにレポートを格納
|
90
|
+
def __write_to_gcs(content,filename):
|
91
|
+
storage_client = storage.Client()
|
92
|
+
bucket_name = 'xxxxxxxx' #ダミー値
|
93
|
+
bucket = storage_client.get_bucket(bucket_name)
|
94
|
+
blob = bucket.blob(filename)
|
95
|
+
blob.upload_from_string(content)
|
96
|
+
|
97
|
+
def get_apple_reports(request):
|
98
|
+
token = __get_apple_store_connect_api_token()
|
99
|
+
vendor_number = 'xxxxxxxx'
|
100
|
+
date_str = None
|
101
|
+
(code, content, date_str) = __get_reports(token, date_str)
|
102
|
+
filename = date_str + '.csv.gz'
|
103
|
+
__write_to_gcs(content,filename)
|
104
|
+
return (None,200,None)
|
105
|
+
|
106
|
+
def get_customer_reviews(event, context):
|
107
|
+
request = {"args": {"date_str": None}}
|
108
|
+
get_apple_reports(request)
|
25
109
|
```
|
26
110
|
|
27
111
|
### 試したこと・調べたこと
|
@@ -31,12 +115,10 @@
|
|
31
115
|
- [ ] その他
|
32
116
|
|
33
117
|
##### 上記の詳細・結果
|
34
|
-
|
118
|
+
取り込めない理由はエラー文から断定はできない。
|
35
|
-
|
119
|
+
仮説通り特殊文字のせいだとするならば、具体的に引っかかっていると推測している文字は「●」で、出力結果に残ってしまう。
|
36
|
-
|
120
|
+
恐らくこの文字↓
|
37
|
-
もとの文章 悪くは無いが不満点も多い
|
38
|
-
|
121
|
+
https://lets-emoji.com/black-circle-emoji/
|
39
|
-
UTF-8変換後 悪く�?無�?��不満点も多い ※文字化けが残ってしまう
|
40
122
|
|
41
123
|
### 補足
|
42
124
|
特になし
|
1
タグの追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|