我在Swift中遇到以下错误,任何人都可以建议或给出解决方案。
SUCCESS: {
error = {
code = 401;
message = "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.";
status = UNAUTHENTICATED;
};
}
我正在使用firebase发送推送通知。
答案 0 :(得分:0)
func sendPushNotification(message:String) -> ()
{
let postParams = ["to":"Set here your receiver push id ","priority":"high","notification":["title":"Title","sound":"default","text":"YourMessage"]] as [String : Any]
var request = URLRequest(url: URL.init(string: "https://fcm.googleapis.com/fcm/send")!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("key=getkey form firebase consol", forHTTPHeaderField: "Authorization")
request.httpBody = try! JSONSerialization.data(withJSONObject: postParams, options: [])
URLSession.shared.dataTask(with: request, completionHandler: { (responseData, response, responseError) -> Void in
if response?.StatusCode == 200
{
}
}).resume();
}