GetStream / swift-activity-feed

Stream Swift iOS Activity Feed Components
https://getstream.io/
BSD 3-Clause "New" or "Revised" License
30 stars 17 forks source link

JSON decoding error #11

Closed AndrewRudyk closed 4 years ago

AndrewRudyk commented 4 years ago

Hello. I have lates version Swift-activity-feed (2.2.3). Initialization and UserRegistration is successful. When I am trying to load Activity I have an error: "JSON decoding error: The data couldn’t be read because it isn’t in the correct format.." JSON in logs is readable and has all the info about my Activitys(Posts).

I use code for request: guard let feedId = FeedId(feedSlug: "timeline") else { return } let timelineFlatFeed = Client.shared.flatFeed(feedId) let presenter = FlatFeedPresenter(flatFeed: timelineFlatFeed)

    presenter.load { (error) in
       if let error = error {
            print("error: ", error)
        } else {
            print(presenter.items)
        }
    }
b-onc commented 4 years ago

Hello @AndrewRudyk Can you please enable and share all logs with us?

AndrewRudyk commented 4 years ago

Stream Feed v.2.2.3 🔑 4x2h5rkwczkz 🔗 https://api.stream-io-api.com/api/v1.0/ 🐴 [25/06 18:42:33.994] 🧹 Disconnect. Reset Client User, Token, URLSession and WebSocket. Old user id: . 👤 User id: 🀄️ Token: 🐴 [25/06 18:42:33.997] ➡️ create(GetStreamActivityFeed.User, true) 🐴 [25/06 18:42:33.999] 🧾 Request Data: { "id" : "tgDePuwzVZha9Ankw2Hu", "data" : { "name" : "tefjg", "profileImage" : null } } 🐴 [25/06 18:42:33.999] 🧾 URL parameters: ["get_or_create": true] 🐴 [25/06 18:42:34.633] ⬅️ Response 201: https://api.stream-io-api.com/api/v1.0/user/?api_key=4x2h5rkwczkz&get_or_create=1 🐴 [25/06 18:42:34.633] ⒿⓈⓄⓃ 180 bytes { "duration" : "0.75ms", "id" : "tgDePuwzVZha9Ankw2Hu", "data" : { "name" : "tefjg", "profileImage" : null }, "updated_at" : "2020-06-25T08:08:31.367794Z", "created_at" : "2020-06-25T08:08:31.367794Z" } 🐴 [25/06 18:42:34.636] 👤 The current user was setupped with id: tgDePuwzVZha9Ankw2Hu 2020-06-25 18:42:34.663891+0300 Bands[6515:2638594] 6.27.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled 🐴 [25/06 18:42:45.775] ➡️ get(feed_one_flat:tgDePuwzVZha9Ankw2Hu, true, GetStream.Pagination.none, "", GetStream.FeedMarkOption.none, GetStream.FeedReactionsOptions(rawValue: 13)) 🐴 [25/06 18:42:45.775] 🧾 Parameters: ["withReactionCounts": true, "withOwnReactions": true, "withRecentReactions": true] 🐴 [25/06 18:42:45.953] ⬅️ Response 200: https://api.stream-io-api.com/api/v1.0/enrich/feed/feed_one_flat/tgDePuwzVZha9Ankw2Hu/?api_key=4x2h5rkwczkz&withOwnReactions=1&withReactionCounts=1&withRecentReactions=1 🐴 [25/06 18:42:45.953] ⒿⓈⓄⓃ 2582 bytes { "results" : [ { "id" : "e49bb837-b225-11ea-bc46-1254437355c5", "reaction_counts" : {

  },
  "verb" : "add",
  "descriptionText" : "Caption (optional)",
  "posterProfileId" : "tgDePuwzVZha9Ankw2Hu",
  "time" : "2020-06-19T12:10:40.716601",
  "postType" : "Photo",
  "latest_reactions" : {

  },
  "imageIds" : [
    "cePH464cjkPaWZMu4MAL",
    "wyv5rnziWKNm6uXYKubk",
    "yhTw4GsVxJSS7tAUZhXx",
    "UdwYui5WpVMadrgxgajs",
    "Upzdv5LGR68Rp9JCeVCu"
  ],
  "object" : "956c39krs48BHviSfZ5S",
  "actor" : "tgDePuwzVZha9Ankw2Hu",
  "origin" : null,
  "latest_reactions_extra" : {

  },
  "own_reactions" : {

  },
  "postId" : "956c39krs48BHviSfZ5S",
  "target" : "",
  "titleText" : "sdf",
  "foreign_id" : ""
},
{
  "id" : "8336377c-b21f-11ea-ad2a-122f0bb6aafb",
  "reaction_counts" : {

  },
  "verb" : "add",
  "descriptionText" : "(optional)",
  "posterProfileId" : "tgDePuwzVZha9Ankw2Hu",
  "time" : "2020-06-19T11:25:00.332019",
  "postType" : "Photo",
  "latest_reactions" : {

  },
  "imageIds" : [
    "Xr675nXccs5ezj2baD2T"
  ],
  "object" : "310d4JXPjPYcsdTjajek",
  "actor" : "tgDePuwzVZha9Ankw2Hu",
  "origin" : null,
  "latest_reactions_extra" : {

  },
  "own_reactions" : {

  },
  "postId" : "310d4JXPjPYcsdTjajek",
  "target" : "",
  "titleText" : "sdfsdf",
  "foreign_id" : ""
},
{
  "id" : "164d1d06-b20d-11ea-9dd0-122f0bb6aafb",
  "reaction_counts" : {

  },
  "verb" : "add",
  "descriptionText" : "(optional)",
  "posterProfileId" : "tgDePuwzVZha9Ankw2Hu",
  "time" : "2020-06-19T09:13:06.669287",
  "postType" : "Photo",
  "latest_reactions" : {

  },
  "imageIds" : [
    "XjKCiuGWqGkAteXv9QY7"
  ],
  "object" : "27ff9a2P2mKhCWJGjf9g",
  "actor" : "tgDePuwzVZha9Ankw2Hu",
  "origin" : null,
  "latest_reactions_extra" : {

  },
  "own_reactions" : {

  },
  "postId" : "27ff9a2P2mKhCWJGjf9g",
  "target" : "",
  "titleText" : "sdfsdfsdf",
  "foreign_id" : ""
},
{
  "id" : "bb64feaf-b208-11ea-a077-1254437355c5",
  "reaction_counts" : {

  },
  "verb" : "add",
  "descriptionText" : "(optional)",
  "posterProfileId" : "tgDePuwzVZha9Ankw2Hu",
  "time" : "2020-06-19T08:41:56.166213",
  "postType" : "Photo",
  "latest_reactions" : {

  },
  "imageIds" : [
    "6xVx9XpTjcDVHuhLNnRZ"
  ],
  "object" : "0c11eZyqCPcKd9RVP495",
  "actor" : "tgDePuwzVZha9Ankw2Hu",
  "origin" : null,
  "latest_reactions_extra" : {

  },
  "own_reactions" : {

  },
  "postId" : "0c11eZyqCPcKd9RVP495",
  "target" : "",
  "titleText" : "sdfsdf",
  "foreign_id" : ""
},
{
  "id" : "969fe47b-b208-11ea-92b8-0a0d7a10423a",
  "reaction_counts" : {

  },
  "verb" : "add",
  "descriptionText" : "(optional)",
  "posterProfileId" : "tgDePuwzVZha9Ankw2Hu",
  "time" : "2020-06-19T08:40:54.476505",
  "postType" : "Photo",
  "latest_reactions" : {

  },
  "imageIds" : [
    "VDudUng3pK5xAmYCcAMw"
  ],
  "object" : "c43edsryYwgx9WEbzPEM",
  "actor" : "tgDePuwzVZha9Ankw2Hu",
  "origin" : null,
  "latest_reactions_extra" : {

  },
  "own_reactions" : {

  },
  "postId" : "c43edsryYwgx9WEbzPEM",
  "target" : "",
  "titleText" : "sdfsdfsd",
  "foreign_id" : ""
}

], "next" : "", "duration" : "10.85ms" } GetStreamService getPosts error: JSON decoding error: The data couldn’t be read because it isn’t in the correct format.. Data: 2582 bytes

AndrewRudyk commented 4 years ago

I had a deeper look at your Framework. I have error in line 54, file "Result+ParseResponse.swift" (GetStream -> Core): ▿ JSON decoding error: The data couldn’t be read because it isn’t in the correct format.. Data: 2582 bytes ▿ jsonDecode : 3 elements

b-onc commented 4 years ago

Hello @AndrewRudyk How did you create the posts on this feed? Can you share the code you've created to post on that feed?

AndrewRudyk commented 4 years ago

Hi @b-onc The following code is called on the server:

const activity = {
      actor: `${posterProfileId}`,
      verb: 'add',
      object: postId,
      postId,
      posterProfileId,
      descriptionText,
      titleText,
      postType,
    };
const client = stream.connect(apiKey, secret, appId, { location: 'us-east' });
    const userFeed = client.feed('feed_one_flat', `${posterProfileId}`);
    await userFeed.addActivity(activity);
b-onc commented 4 years ago

@AndrewRudyk the argument

actor: `${posterProfileId}`,

is causing the error. actor field expects a full user. You can use SDK to post some stuff, then inspect the getPost result's actor field to see how our SDK posts.

AndrewRudyk commented 4 years ago

@b-onc what is it "full user"? JSON hasn't empty fields with "actor".

b-onc commented 4 years ago

@AndrewRudyk actor fields expects a user object, such as:

"actor" : {
        "id" : "dconroy",
        "data" : null,
        "updated_at" : "2020-01-18T07:59:53.958398Z",
        "created_at" : "2020-01-18T07:59:53.958398Z"
      }
AndrewRudyk commented 4 years ago

@b-onc We have example from documentation where the "string" is required and this works well on the our website and Android SDK: https://getstream.io/docs/adding_activities/?language=js image

AndrewRudyk commented 4 years ago

We can only send:

"actor" : {
        "id" : "dconroy",

?

b-onc commented 4 years ago

@AndrewRudyk actor can be a string, but GetStreamActivityFeed expects the user object so it can display data regarding it. The examples are usable via the GetStream pod, our Core library for Stream Feeds. If you want to use GetStreamActivityFeed library, actor should be a user object.

"actor" : {
        "id" : "tgDePuwzVZha9Ankw2Hu",
        "data": {
                "name": "User Name", // can be null
                "profileImage": null
        }
}

would work. If you pass null for name, user name won't be visible in GetStreamActivityFeed UI.

AndrewRudyk commented 4 years ago

@b-onc Hi We are trying to send an object in actor property on the backend. Here is code snippet from the backend:

const stream = require('getstream');
const client = stream.connect(
  process.env.GET_STREAM_API_KEY,
  process.env.GET_STREAM_API_SECRET,
  process.env.GET_STREAM_APP_ID,
);
const getClient = () => client;
const getFeed = (id) => client.feed('feed_one_flat', id);
const activity = {
    actor: {
      id: posterProfileId,
      data: {
        name: null,
        profileImage: null,
      },
    },
    verb: 'add',
    object: postId,
    foreign_id: postId,
    time: createdAt,
    postId,
    posterProfileId,
    descriptionText,
    titleText,
    postType,
  };
  const userFeed = getFeed(posterProfileId);
  const result = await userFeed.addActivity(activity);

In the mobile app we are getting this response and the same error. It look likes actor is still treated as a string, not an object:

{
  "results" : [
    {
      "id" : "35a9e590-bac2-11ea-8080-80003bb39bb0",
      "reaction_counts" : {

      },
      "videoIds" : [
        "PwwzKECB01I01eM4cZsR6m500003ZOFIsagjj8lzSjtZt6E"
      ],
      "verb" : "add",
      "descriptionText" : "dt",
      "posterProfileId" : "w75K3rXL9EF4iuy7rkrW",
      "time" : "2020-06-30T11:09:47.497000",
      "postType" : "BandsPost",
      "latest_reactions" : {

      },
      "imageIds" : [
        "WhctNcSzztTfDQM2KuHC"
      ],
      "object" : "c4c29Pt49gENVQmgzcF3",
      "actor" : "{\"data\":{\"name\":null,\"profileImage\":null},\"id\":\"w75K3rXL9EF4iuy7rkrW\"}",
      "origin" : null,
      "latest_reactions_extra" : {

      },
      "own_reactions" : {

      },
      "postId" : "c4c29Pt49gENVQmgzcF3",
      "target" : "",
      "titleText" : "tt",
      "foreign_id" : "c4c29Pt49gENVQmgzcF3"
    }
  ],
  "next" : "",
  "duration" : "9.05ms"
}

Actor property: "actor" : "{\"data\":{\"name\":null,\"profileImage\":null},\"id\":\"w75K3rXL9EF4iuy7rkrW\"}",