Closed deepak-vishwakarma-spok closed 4 years ago
I ran into this error as well, and was able to work around it by ensuring that the API endpoint returned an enriched actor
attribute, not just a String with an actor ID. In order to do that, I had to make sure that the actor was a string following the format SA:user-id
, where user-id
is some user that actually exists within the Stream application.
Not sure if this is an intentional limitation of the client API. But as it currently stands, the Swift Activity Feed Demo code does not work without enriched actor information in the feed.
Hey @deepak-vishwakarma-spok Demo project, adding activity works for me now. @levmar : The client should use an actor as the current user.
ensuring that the API endpoint returned an enriched
actor
attribute
@levmar @b-onc Thanks for the tip. How does one insure that the API returns the enriched data?
The funny thing is that I've just Hooked the GetStreamActivityFeed
and GetStream
dependencies into my project, I've literally taken the code form the example app and run it and I'm observing the same behaviour.
TextToolBar
component (literally using the same ViewController
code that exists in the demo app❌ JSON decoding error: The data couldn’t be read because it isn’t in the correct format.. Data: 1508 bytes
The funny thing is that I'm not in control of deserialising the response, at least I understand this as the responsibility of your SDK.
The example response:
{
"results": [
{
"id": "adb5cc6f-3aee-11ea-a1e5-0a0d7a10423a",
"reaction_counts": {
},
"verb": "post",
"time": "2020-01-19T19:05:37.922162",
"latest_reactions": {
},
"object": "Test - ",
"actor": {
"id": "138",
"data": null,
"updated_at": "2020-01-12T19:02:04.535043Z",
"created_at": "2020-01-12T19:02:04.535043Z"
},
"origin": null,
"latest_reactions_extra": {
},
"own_reactions": {
},
"target": "",
"foreign_id": ""
},
{
"id": "7323b5e8-3aee-11ea-88d4-12f8ef9c949e",
"reaction_counts": {
},
"verb": "post",
"time": "2020-01-19T19:03:59.656906",
"latest_reactions": {
},
"object": "Test ",
"actor": {
"id": "138",
"data": null,
"updated_at": "2020-01-12T19:02:04.535043Z",
"created_at": "2020-01-12T19:02:04.535043Z"
},
"origin": null,
"latest_reactions_extra": {
},
"own_reactions": {
},
"target": "",
"foreign_id": ""
},
{
"id": "8f8179ef-3aed-11ea-a149-0a0d7a10423a",
"reaction_counts": {
},
"verb": "post",
"time": "2020-01-19T18:57:37.750885",
"latest_reactions": {
},
"object": "The test ",
"actor": {
"id": "138",
"data": null,
"updated_at": "2020-01-12T19:02:04.535043Z",
"created_at": "2020-01-12T19:02:04.535043Z"
},
"origin": null,
"latest_reactions_extra": {
},
"own_reactions": {
},
"target": "",
"foreign_id": ""
},
{
"id": "db787833-3aeb-11ea-8746-12f8ef9c949e",
"reaction_counts": {
},
"verb": "post",
"time": "2020-01-19T18:45:26.205240",
"latest_reactions": {
},
"object": "LePost",
"actor": {
"id": "138",
"data": null,
"updated_at": "2020-01-12T19:02:04.535043Z",
"created_at": "2020-01-12T19:02:04.535043Z"
},
"origin": null,
"latest_reactions_extra": {
},
"own_reactions": {
},
"target": "",
"foreign_id": ""
}
],
"next": "",
"duration": "10.28ms"
}
🤔 any news on this?
@marcoti We were blocked by some other issues but we'll get to this as soon as possible.
Hey @marcoti , @marcfrost and @levmar I've tried to reporduce the error using https://github.com/GetStream/swift-activity-feed-demo but I could not. I've setup a new add and used new credentials, demo app was not working, so I've updated the demo app to work with latest GetStream pod. So far, everything works for me. Can you guys provide more info on this JSON decoding error?
Good to follow the tutorial, too: https://getstream.io/ios-activity-feed/tutorial/
Sure - so I've gone through the tutorial, I think I'm doing what I'm supposed to be. Let me try paint the picture as accurately as possible...
On my getStream developer dashboard:
timeline
key
and app id
at this pointOn my backend:
createUserSessionToken(userId)
user
So let's shift this focus on over to my iOS client implementation:
pod 'GetStreamActivityFeed', '~> 2.2.0'
I believe this is the correct pod version, at least it is based on: https://github.com/GetStream/swift-activity-feedClient.config = .init(apiKey: "xxxxxxxxxxxx", appId: "xxxxx")
So here's what I'm seeing with this very basic setup when navigating to my ViewController that is doing literally nothing but interacting with getStream:
I can see that the call to Client.shared.getCurrentUser
is coming back as a success
👤 User id: 138
🀄️ Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTM4In0.IbGoZUE7jzdjmJsZk4USNQak_v9z0VYfS4BOd7lqlSQ
---------------------
POST 'https://api.stream-io-api.com/api/v1.0/user/?api_key=knwc9xsncjfj&get_or_create=1':
Headers: [
X-Stream-OS : iOS13.3
Authorization : eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTM4In0.IbGoZUE7jzdjmJsZk4USNQak_v9z0VYfS4BOd7lqlSQ
X-Stream-Client : stream-swift-client-2.2.1
X-Stream-Device : iPhone 8
Stream-Auth-Type : jwt
]
{"id":"138"}
---------------------
201 'https://api.stream-io-api.com/api/v1.0/user/?api_key=knwc9xsncjfj&get_or_create=1' [0.4453 s]:
Headers: [
Date : Tue, 28 Jan 2020 20:49:52 GMT
access-control-allow-headers : x-requested-with, content-type, accept, origin, authorization, x-csrftoken, x-stream-client, stream-auth-type
access-control-max-age : 86400
Access-Control-Allow-Origin : *
access-control-allow-methods : GET, POST, PUT, PATCH, DELETE, OPTIONS
Content-Type : application/json;charset=utf-8
x-ratelimit-reset : 1580244600
x-ratelimit-remaining : 999
x-ratelimit-limit : 1000
Content-Length : 129
Cache-Control : no-cache
Server : nginx
]
{
"duration" : "3.85ms",
"id" : "138",
"data" : {
},
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
}
I can see that the call to self.reloadData
results in a successful call to the API:
GET 'https://api.stream-io-api.com/api/v1.0/enrich/feed/timeline/138/?api_key=knwc9xsncjfj&withOwnReactions=1&withReactionCounts=1&withRecentReactions=1':
Headers: [
Authorization : eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTM4In0.IbGoZUE7jzdjmJsZk4USNQak_v9z0VYfS4BOd7lqlSQ
X-Stream-Device : iPhone 8
X-Stream-OS : iOS13.3
Stream-Auth-Type : jwt
X-Stream-Client : stream-swift-client-2.2.1
]
---------------------
200 'https://api.stream-io-api.com/api/v1.0/enrich/feed/timeline/138/?api_key=knwc9xsncjfj&withOwnReactions=1&withReactionCounts=1&withRecentReactions=1' [0.4902 s]:
Headers: [
Content-Type : application/json;charset=utf-8
Server : nginx
access-control-allow-methods : GET, POST, PUT, PATCH, DELETE, OPTIONS
x-ratelimit-remaining : 1999
Date : Tue, 28 Jan 2020 21:02:26 GMT
access-control-max-age : 86400
access-control-allow-headers : x-requested-with, content-type, accept, origin, authorization, x-csrftoken, x-stream-client, stream-auth-type
Content-Length : 384
Cache-Control : no-cache
Content-Encoding : gzip
Access-Control-Allow-Origin : *
x-ratelimit-limit : 2000
x-ratelimit-reset : 1580245380
]
{
"results" : [
{
"id" : "adb5cc6f-3aee-11ea-a1e5-0a0d7a10423a",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T19:05:37.922162",
"latest_reactions" : {
},
"object" : "Test - ",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
},
{
"id" : "7323b5e8-3aee-11ea-88d4-12f8ef9c949e",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T19:03:59.656906",
"latest_reactions" : {
},
"object" : "Test ",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
},
{
"id" : "8f8179ef-3aed-11ea-a149-0a0d7a10423a",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T18:57:37.750885",
"latest_reactions" : {
},
"object" : "The test ",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
},
{
"id" : "db787833-3aeb-11ea-8746-12f8ef9c949e",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T18:45:26.205240",
"latest_reactions" : {
},
"object" : "LePost",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
}
],
"next" : "",
"duration" : "13.44ms"
}
❌ JSON decoding error: The data couldn’t be read because it isn’t in the correct format.. Data: 1508 bytes
I have tried to make a "post" to this "timeline", using this viewController, and I can see by interrogating the response in the logs (like the example posted in the above bullet point) that the post to the timeline was successful 🎉 It's just a shame that we can't deserialise the response.
So to recap:
https://api.stream-io-api.com
this is of course managed by Stream Swift iOS Activity Feed ComponentsGetStreamActivityFeed
SDKGetStreamActivityFeed
SDK cannot deserialise this successful response I've tried to be as detailed as possible but if I've left out some crucial information I'm more than happy to provide more info to help debug this. But it really doesn't seem like I'm doing anything particularly special with any of the above 🤷♂ any help would be appreciated, maybe I'm doing something silly my side - but I'm really surprised to see that JSON decoding error
in the logs. It's OK for there to be a problem processing a response, but it seems less OK that the response can't be deserialised (especially in this case where the repsonse is actually a 200 and contains what looks at a glance to be a perfectly formed payload describing the posts in the timeline.
Side note: I'm aware the logs contain my API key - that's OK it's just a development app I threw together to test out your API + SDK. I'll regenerate it if I pursue this solution further.
Actually I've just pulled the latest codebase on the demo app and I'm seeing the exact same behaviour that side:
The below is 100% reproducible on the current head:
commit dc079d76b516403e111aed7149e37ce891035cbb (HEAD -> master, origin/master, origin/HEAD)
Take my development stream application
to help you on your journey:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Setup Stream Client.
Client.config = .init(apiKey: "knwc9xsncjfj", appId: "67189", logsEnabled: true)
Client.shared.setupUser(GetStreamActivityFeed.User(name: "Test",
id: "138"),
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTM4In0.IbGoZUE7jzdjmJsZk4USNQak_v9z0VYfS4BOd7lqlSQ") { (result) in
guard result.error == nil else {
preconditionFailure("Cannot setup user: \(result.error!)")
}
if let viewController = self.window?.rootViewController as? ViewController {
viewController.reloadData()
}
}
return true
}
}
Stream Feed v.2.2.1
🔑 knwc9xsncjfj
🔗 https://api.stream-io-api.com/api/v1.0/
🐴 [28/01 22:03:12.695] 🧹 Disconnect. Reset Client User, Token, URLSession and WebSocket. Old user id: <Empty>.
👤 User id: 138
🀄️ Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTM4In0.IbGoZUE7jzdjmJsZk4USNQak_v9z0VYfS4BOd7lqlSQ
🐴 [28/01 22:03:12.699] ➡️ create(GetStreamActivityFeed.User, true)
🐴 [28/01 22:03:12.700] 🧾 Request Data:
{
"id" : "138",
"data" : {
"name" : "Test",
"profileImage" : null
}
}
🐴 [28/01 22:03:12.700] 🧾 URL parameters: ["get_or_create": true]
🐴 [28/01 22:03:12.741] ➡️ get(timeline:138, true, GetStream.Pagination.none, "", GetStream.FeedMarkOption.none, GetStream.FeedReactionsOptions(rawValue: 13))
🐴 [28/01 22:03:12.741] 🧾 Parameters: ["withReactionCounts": true, "withOwnReactions": true, "withRecentReactions": true]
🐴 [28/01 22:03:13.257] ⬅️ Response 201: https://api.stream-io-api.com/api/v1.0/user/?api_key=knwc9xsncjfj&get_or_create=1
🐴 [28/01 22:03:13.257] ⒿⓈⓄⓃ 129 bytes
{
"duration" : "0.75ms",
"id" : "138",
"data" : {
},
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
}
🐴 [28/01 22:03:13.260] 👤 The current user was setupped with id: 138
🐴 [28/01 22:03:13.260] ➡️ get(timeline:138, true, GetStream.Pagination.none, "", GetStream.FeedMarkOption.none, GetStream.FeedReactionsOptions(rawValue: 13))
🐴 [28/01 22:03:13.260] 🧾 Parameters: ["withRecentReactions": true, "withOwnReactions": true, "withReactionCounts": true]
🐴 [28/01 22:03:13.270] ⬅️ Response 200: https://api.stream-io-api.com/api/v1.0/enrich/feed/timeline/138/?api_key=knwc9xsncjfj&withOwnReactions=1&withReactionCounts=1&withRecentReactions=1
🐴 [28/01 22:03:13.270] ⒿⓈⓄⓃ 1872 bytes
{
"results" : [
{
"id" : "7ad53f41-4219-11ea-8e45-0a0d7a10423a",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-28T21:59:39.063277",
"latest_reactions" : {
},
"object" : "Hmmm.",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
},
{
"id" : "adb5cc6f-3aee-11ea-a1e5-0a0d7a10423a",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T19:05:37.922162",
"latest_reactions" : {
},
"object" : "Test - ",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
},
{
"id" : "7323b5e8-3aee-11ea-88d4-12f8ef9c949e",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T19:03:59.656906",
"latest_reactions" : {
},
"object" : "Test ",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
},
{
"id" : "8f8179ef-3aed-11ea-a149-0a0d7a10423a",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T18:57:37.750885",
"latest_reactions" : {
},
"object" : "The test ",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
},
{
"id" : "db787833-3aeb-11ea-8746-12f8ef9c949e",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T18:45:26.205240",
"latest_reactions" : {
},
"object" : "LePost",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
}
],
"next" : "",
"duration" : "10.40ms"
}
❌ JSON decoding error: The data couldn’t be read because it isn’t in the correct format.. Data: 1872 bytes
🐴 [28/01 22:03:13.396] ⬅️ Response 200: https://api.stream-io-api.com/api/v1.0/enrich/feed/timeline/138/?api_key=knwc9xsncjfj&withOwnReactions=1&withReactionCounts=1&withRecentReactions=1
🐴 [28/01 22:03:13.396] ⒿⓈⓄⓃ 1872 bytes
{
"results" : [
{
"id" : "7ad53f41-4219-11ea-8e45-0a0d7a10423a",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-28T21:59:39.063277",
"latest_reactions" : {
},
"object" : "Hmmm.",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
},
{
"id" : "adb5cc6f-3aee-11ea-a1e5-0a0d7a10423a",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T19:05:37.922162",
"latest_reactions" : {
},
"object" : "Test - ",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
},
{
"id" : "7323b5e8-3aee-11ea-88d4-12f8ef9c949e",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T19:03:59.656906",
"latest_reactions" : {
},
"object" : "Test ",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
},
{
"id" : "8f8179ef-3aed-11ea-a149-0a0d7a10423a",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T18:57:37.750885",
"latest_reactions" : {
},
"object" : "The test ",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
},
{
"id" : "db787833-3aeb-11ea-8746-12f8ef9c949e",
"reaction_counts" : {
},
"verb" : "post",
"time" : "2020-01-19T18:45:26.205240",
"latest_reactions" : {
},
"object" : "LePost",
"actor" : {
"id" : "138",
"data" : null,
"updated_at" : "2020-01-12T19:02:04.535043Z",
"created_at" : "2020-01-12T19:02:04.535043Z"
},
"origin" : null,
"latest_reactions_extra" : {
},
"own_reactions" : {
},
"target" : "",
"foreign_id" : ""
}
],
"next" : "",
"duration" : "10.62ms"
}
❌ JSON decoding error: The data couldn’t be read because it isn’t in the correct format.. Data: 1872 bytes
Hello @marcfrost Thanks for sharing lots of info! I can reproduce your issue easily. The issue is not reproducible on a clear feed, the problem comes from the JSON you're getting. When you setup the user with:
Client.shared.setupUser(token: userAccount.socialUserToken) { result in
self.reloadData()
}
you'll use the default user type (GetStream.User
). But TextToolBar
expects GetStreamActivityFeed.User
to operate. That's why if you setup a new user with setupUser(token:)
, you won't be able to post anything on the demo app, you'll get the warning:
❌ The current user not found
When I create a new (demo) app (without any code changes), and post some stuff, in the results' actor
I see:
"actor" : {
"id" : "138",
"data" : {
"name" : "Test",
"profileImage" : null
},
"updated_at" : "2020-01-29T09:55:18.112781Z",
"created_at" : "2020-01-29T09:55:18.112781Z"
}
but in your logs, I see that data
is null. If you've used a custom user type, can you share it? If you haven't, I suspect the problem comes from using setupUser(token:)
and posting some stuff (without using GetStreamActivityFeed
), then using demo app (which uses setupUser(user:token:)
and gets enriched activities) to try fetching the posts. It'd be good to know how were the activities in the JSON were created in the first place, so we can get to the bottom of this issue.
The issues people are facing in this thread surfaced a logging problem: this should've been made clearer in the docs and the log outputs. We'll work on improving the error messages. Probably we've made some changes and did not document them enough.
Let me know if this makes things clear.
Thanks @b-onc that's been super helpful.
I've re-created a new stream development application
to test and all is working quite well thanks. I suspect i posted those additional entries while I was testing the getstream pod (as opposed to GetStreamActivityFeed
) - appreciate you took the time to help out with this 🙌
Can you please check if add activity working . I added my stream key , app id and tokien. When trying to add activity getting decoding error . but activity are getting saved successfully. Below is the error on console coming
unexpectedError(Optional(GetStream.ClientError.jsonDecode("The data couldn’t be read because it isn’t in the correct format.", Optional(Swift.DecodingError.typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "actor", intValue: nil)], debugDescription: "Expected to decode Dictionary<String, Any> but found a string/data instead.", underlyingError: nil))), 224 bytes)))