Для перехода от предыдущего HTTP к HTTP v1, oauth 2.0
To-To-To-To-To-To-To-To-Tosken. /> < /blockquote>
Однако я не уверен, как получить этот токен. < /p>
текущий код < /p>
Код: Выделить всё
func(){
let serverKey:String = "AAAAA"
let url = URL(string: "https://fcm.googleapis.com/fcm/send")!
let userIdToken:String = userIdToken
var request = URLRequest(url: url)
let postMessage: [String: Any] = [
"to": userIdToken,
"priority": "high",
"content_available" : true,
"notification": [
"badge": 1,
"body": body,
"title": title
] as [String : Any]
]
request.httpMethod = "POST"
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.setValue("key=\(serverKey)", forHTTPHeaderField: "Authorization")
:
:
< /code>
Код, который я попробовал < /p>
func(){
//let serverKey:String = "AAAAA"
//add
let url = URL(string: "https://fcm.googleapis.com/v1/projects/myproject/messages:send")!
let userIdToken:String = userIdToken
var request = URLRequest(url: url)
let postMessage: [String: Any] = [
"to": userIdToken,
"priority": "high",
"content_available" : true,
"notification": [
"badge": 1,
"body": body,
"title": title
] as [String : Any]
]
/* I would like to know the solusion. */
//add
let accessToken:String = getOAuth2AccessToken()
request.httpMethod = "POST"
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
//request.setValue("key=\(serverKey)", forHTTPHeaderField: "Authorization")
//add
request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
:
:
< /code>
Я хочу кодировать это (getOAuth2AccessToken()
Подробнее здесь: https://stackoverflow.com/questions/784 ... to-http-v1