Unable to parse Measurement Protocol JSON payload - google-analytics

I am trying to send a post payload however I was returned an error, can advise?
tracking_id is the id that I am using.
url = "https://www.google-analytics.com/debug/mp/collect"
payload = {
"v": 1,
"tid": tracking_id,
"cid": 555,
"t": "event",
"ec": "download",
"ea": "file_download",
"el": data['file_name'],
"ev": 1,
"cd5": data['hash']
}
response = requests.post(url, data=payload)
print(response.text)
Error message
{
"validationMessages": [ {
"description": "Unable to parse Measurement Protocol JSON payload. invalid JSON in google.analytics.measurement.Measurement, near 1:1 (offset 0): unexpected character: 'v'; expected '{'",
"validationCode": "VALUE_INVALID"
} ]
}

Related

MirageJS Error response not causing an error

Following the docs I've set up this handler inside routes():
this.put(
'/admin/features/error/environment/test',
// #ts-ignore
() => new Response(500, {}, { errors: ['The database went on vacation'] }),
);
Mirage does receive what I've set, sort of. Here is its response, from the browser console logs. Note that it's not an error although the 500 shows up in _bodyInit:
{
"type": "default",
"status": 200,
"ok": true,
"statusText": "",
"headers": {
"map": {
"content-type": "text/plain;charset=UTF-8"
}
},
"url": "",
"bodyUsed": false,
"_bodyInit": 500,
"_bodyText": "[object Number]"
}
Note that I need ts-ignore which is probably a clue. TS complains that new Response expects 0-2 arguments but got 3.
Try importing the Mirage Response class:
import { Response } from 'miragejs';
Otherwise, Response refers to a Fetch API Response object. This explains the type checking error and the unexpected behavior when calling the route.
After adding the import you can remove #ts-ignore and requests to the route should fail with status code 500.

The request body contains invalid JSON

I'm trying to POST to a discord webhook URL using Python Requests but whenever the embeds field is present, it returns {'code': 50109, 'message': 'The request body contains invalid JSON.'}. If I remove embeds and just leave content it will send without any errors.
My code is:
url = "https://discord.com/api/webhooks/[redacted]/[redacted]"
headers = {
"Content-Type": "application/json"
}
data = {
"username": "Webhook",
"content": "Hello, World!",
"embeds": [{
"title": "Hello, Embed!",
"description": "This is an embedded message."
}]
}
res = requests.post(url, headers=headers, data=data)
I've tried various version of the Discord API but the result is always the same.
I got it working by replacing
requests.post(url, headers=headers, data=data)
with
requests.post(url, json=data)
Try this. I think the requests library may be adding a header called content-type which conflicts with your header Content-Type, which makes the Discord API return an error:
url = "https://discord.com/api/webhooks/[redacted]/[redacted]"
headers = {
"content-type": "application/json"
}
data = {
"username": "Webhook",
"content": "Hello, World!",
"embeds": [{
"title": "Hello, Embed!",
"description": "This is an embedded message."
}]
}
res = requests.post(url, headers=headers, json=data)

firebase.getToken() not a valid token

The function that gives me the registration Token returns the following string
eyJhbGciOiJSUzI1NiIsImtpZCI6ImQyZjQ0ZGVmNmE5MDkyYzlhYmYwNzJiMzM3ZDQ3OTVkZTFmZmNjY2UifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vZGFyay1zdHJhdHVtLTE5NDAxOSIsImF1ZCI6ImRhcmstc3RyYXR1bS0xOTQwMTkiLCJhdXRoX3RpbWUiOjE1MTgxNzUzODcsInVzZXJfaWQiOiI1YTY5ZTM4NjEzZWJkYmU4MGQ0MzhiOTciLCJzdWIiOiI1YTY5ZTM4NjEzZWJkYmU4MGQ0MzhiOTciLCJpYXQiOjE1MTgxNzUzODgsImV4cCI6MTUxODE3ODk4OCwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6e30sInNpZ25faW5fcHJvdmlkZXIiOiJjdXN0b20ifX0.rN76re5hzXkf03MFezbE5fvqJQ0XR46HZNOm9vAlPYr5hdr5LxP7Abbu5QK733WXVtwENwcv86HH2Q_jfxMlAzKwQRlHcU9g7-2wS1Q-jPIDfmc9-DziR4IgtrmJ3wt3mKl-3yS60PJdNhXOsg0PEt70GoWwEsaIsti4MEw87c470z9M8YRtCS_Q7yeEBZCs0MOTUmvfiFLVkrboPEgOf9zv7GFfRAuF3Zt-qOx9I-4GdUksuA2_mFCXXUEZ_eHkEWEdNl_wCT1ggMy7VMlQgFmRl00FXEgGSUIBLghejGDuJFT08CVsh5oLrHp2pKNSIShRnmL9RLJgnXTEzUz39A
whene I use this string as a token to send message it gives me an error :
{
"results": [
{
"error": {
"code": "messaging/invalid-registration-token",
"message": "Invalid registration token provided. Make sure it matches the registration token the client app receives from registering with FCM."
}
}
],
"canonicalRegistrationTokenCount": 0,
"failureCount": 1,
"successCount": 0,
"multicastId": 5998201396286625000
}
I think the registration token should be in this format :
cbuJIjkg9zQ:APA91bHavuWCuRuWIBrDOoHUK-RsjU1yewigurrYzHe0cP‌​iTQINykKjrLf8E0qEwJj‌​3XmJ1IoTmn0r2EoLR_mA‌​HGOjlA61CnQ8aSn2WxWK‌​KByOwbsnqoVeaeWQIeGU‌​_yh4wnZ67soLtI

How to determine which device is not registered

How to determine which particular device is "NotRegisterd".
I send message to some butch of devices. Here my body:
{
"registration_ids": ["someCode1", "someCode2", "someCode3"],
"notification": {...},
"data": {...}
}
And got response:
{
"multicast_id": 6613705169343972705,
"success": 1,
"failure": 2,
"canonical_ids": 0,
"results": [
{
"error": "NotRegistered"
},
{
"message_id": "0:1496749257460993%5fe3e4105fe3e410"
},
{
"error": "NotRegistered"
}]
}
How to determine which devices not registered?
I have only one idea. The order of registration_ids is equal order of results.
In Table 5 of the HTTP Server Protocol documentation it describes the results array as:
Array of objects representing the status of the messages processed.
The objects are listed in the same order as the request (i.e., for
each registration ID in the request, its result is listed in the same
index in the response)
So your guess is correct, the order of the results is the same order as the registration IDs.

SWIFT 3 Post request with VIEWSTATE

I need to log in example.com/mobile/shared/default.aspx by using POST request
How do i get current ViewState and sending it after?
That is what i tried
(Alamofire)
func webRequest()
{
let parameters: Parameters = [
"name": "name",
"password": "password",
"enter": "Enter",
]
Alamofire.request("http://example.ru/mobile/shared/default.aspx", parameters: parameters).responseJSON { response in
print(response.request) // original URL request
print(response.response) // HTTP URL response
print(response.data) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
}
I'm using Alamofire like this:
let Parameters = [
"name": "name",
"password": "password",
"enter": "Enter"]
var json : JSON = nil
Alamofire.request(URLString, method: method, parameters: Parameters)
.responseJSON { response in
switch response.result {
case .success(let data):
json = JSON(data)
print(json)
case .failure(let error):
print("Request failed with error: \(error)")
}
}
}
So after that you can parse your json like this for example:
if json != nil {
let token = json["token"].stringValue
}
But all of that depend of your server request params, and request response from your server.
Hope I helped you, Peace

Resources