How to identify the user to whom the webhook has been received in Account Acitivity webhook notification response?

account-activity

#1

Account Activity webhook response:
Ex:
direct_message_events :slight_smile:

{“direct_message_events”:[{“type”:“message_create”,“id”:“959734837547474950”,“created_timestamp”:“1517653590939”,“message_create”:{“target”:{“recipient_id”:“2814576702”},“sender_id”:“1605225529”,“source_app_id”:“268278”,“message_data”:{“text”:“DM https://t.co/0FpmWgpyTc",“entities”:{“hashtags”:[],“symbols”:[],“user_mentions”:[],“urls”:[{“url”:“https://t.co/0FpmWgpyTc”,“expanded_url”:“https://twitter.com/AdolfHitlerJi/status/959734484986769409”,“display_url”:“twitter.com/AdolfHitlerJi/\u2026”,“indices”:[3,26]}]}}}}],“apps”:{“268278”:{“id”:“268278”,“name”:"Twitter Web Client”,“url”:“http://twitter.com”}},“users”:{“1605225529”:{“id”:“1605225529”,“created_timestamp”:“1374213581965”,“name”:“rajeswari”,“screen_name”:“RajiitGct”,“location”:“chennai”,“description”:“I’m a socialuser. :)”,“protected”:false,“verified”:false,“followers_count”:37,“friends_count”:38,“statuses_count”:1517,“profile_image_url”:“http://pbs.twimg.com/profile_images/420493852059783168/qeV8cvWG_normal.jpeg",“profile_image_url_https”:“https://pbs.twimg.com/profile_images/420493852059783168/qeV8cvWG_normal.jpeg”},“2814576702”:{“id”:“2814576702”,“created_timestamp”:“1410946836295”,“name”:“Rajeswari”,“screen_name”:“AdolfHitlerJi”,“protected”:false,“verified”:false,“followers_count”:5,“friends_count”:14,“statuses_count”:323,“profile_image_url”:“http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png”,“profile_image_url_https”:"https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png”}}}

Here how can I idenetify to which user we received dthis webhook notification? Any key is there or in headers ?


#2

Team, Anyone clarify this pls.


#3

If you are looking for the sender_id or recipient_id, both are located within the json payload.

If you are looking for something different, please clarify.


#4

If my application have registered with these two twitter account. How to identify in which twitter account we received this notification and by using which key? Here you can say based on which key I can identify the webhook receiving user?


#5

If you are looking for the sender_id or recipient_id, both are located within the json payload.

sender_id and recipient_id is based on dm send and receive.we will receive notification even when webhook registered user sends dm to other users right? Then how can we process based on sender_id or receipient_id ?


#6

In old streaming api we will receive “for” key to identify to which user we are receiving stream response. Likewise how to identify in new account activity webhook response for all the activities?


#9

@RajiitGct -
The payload will have user object details for example:

 "user": {
         "id": 20112314406,

So, each event type will be called out clearly, this is a Tweet create event:

{
   "tweet_create_events": [
     {
       "created_at": "Tue Feb 06 17:29:45 +0000        "id": 960928513174880300,
       "id_str": "960928513174880257",
       "text": "Hello gold dome :) https://t.co/n0mR8UjKvU",
       "display_text_range": [
         0,
         18
       ],
       "source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter for  iPhone</a>",
       "truncated": false,
       "in_reply_to_status_id": null,
       "in_reply_to_status_id_str": null,
       "in_reply_to_user_id": null,
       "in_reply_to_user_id_str": null,
       "in_reply_to_screen_name": null,
       "user": {
         "id": 20114406,

With a user id in the User object.

Please let us know if you are seeing something different.

Thanks!


#10

This user object who did the action right? For example if some one replied to my tweet (subscribed account) , this user object will have that person’s id not mine.


#11

Can anyone know about this? How can we identify the user in above mentioned cases?


#12

You’ve already answered your own question, yes, the user object will refer to the user that took that action.


#13

@andypiper In the above kind of cases , how can we identify the user whom we are receiving the object? (If two user involved in the action) .


#14

Here’s what a Direct Message object looks like - note the target/recipient_id, and sender_id fields.

{
  "direct_message_events": [
    {
      "type": "message_create",
      "id": "982251301340725253",
      "created_timestamp": "1523021934243",
      "message_create": {
        "target": {
          "recipient_id": "786491"
        },
        "sender_id": "54931584",
        "message_data": {
          "text": "testing",
          "entities": {
            "hashtags": [],
            "symbols": [],
            "user_mentions": [],
            "urls": []
          }
        }
      }
    }
  ],
  "users": {
    "786491": {
      "id": "786491",
      "created_timestamp": "1172070888000",
      "name": "andy piper (pipes)",
      "screen_name": "andypiper",
      "location": "Kingston upon Thames, London",
      "description": "Historian. I mostly live online. lead human @TwitterDev @twitterapi platform - qs via https://t.co/DVDf7qKyS9. Community & respect. ⌨️ 🙇 #HeForShe 🏳️‍🌈",
      "url": "https://t.co/jHwGP7KDmZ",
      "protected": false,
      "verified": false,
      "followers_count": 15574,
      "friends_count": 3343,
      "statuses_count": 109857,
      "profile_image_url": "http://pbs.twimg.com/profile_images/822290883001389057/y3eNJQPh_normal.jpg",
      "profile_image_url_https": "https://pbs.twimg.com/profile_images/822290883001389057/y3eNJQPh_normal.jpg"
    },
    "54931584": {
      "id": "54931584",
      "created_timestamp": "1247067642000",
      "name": "Evil Piper",
      "screen_name": "evilpiper",
      "description": "mwah-ha-haaaaa (aka, squirrel!)",
      "protected": false,
      "verified": false,
      "followers_count": 31,
      "friends_count": 22,
      "statuses_count": 689,
      "profile_image_url": "http://pbs.twimg.com/profile_images/860122276469116929/k3npzTav_normal.jpg",
      "profile_image_url_https": "https://pbs.twimg.com/profile_images/860122276469116929/k3npzTav_normal.jpg"
    }
  }
}

#15

@andypiper @LeBraat
I have subscribed two users for a webhook url. I had mentioned one user in another user’s tweet and got same response payload for two times from webhook. How do I identify the user to whom the response has been received.

Sample response

{
  "tweet_create_events": [
    {
      "created_at": "Thu Apr 12 06:37:12 +0000 2018",
      "id": 984319503453642752,
      "id_str": "984319503453642752",
      "text": "mention tweet testing when both the users are subscribed @R_Amsaveni",
      "source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>",
      "truncated": false,
      "in_reply_to_status_id": null,
      "in_reply_to_status_id_str": null,
      "in_reply_to_user_id": null,
      "in_reply_to_user_id_str": null,
      "in_reply_to_screen_name": null,
      "user": {
        "id": 949259913468903427,
        "id_str": "949259913468903427",
        "name": "sample",
        "screen_name": "Sample2511",
        "location": null,
        "url": null,
        "description": null,
        "translator_type": "none",
        "protected": false,
        "verified": false,
        "followers_count": 1,
        "friends_count": 0,
        "listed_count": 0,
        "favourites_count": 3,
        "statuses_count": 26,
        "created_at": "Fri Jan 05 12:42:54 +0000 2018",
        "utc_offset": null,
        "time_zone": null,
        "geo_enabled": false,
        "lang": "en",
        "contributors_enabled": false,
        "is_translator": false,
        "profile_background_color": "F5F8FA",
        "profile_background_image_url": "",
        "profile_background_image_url_https": "",
        "profile_background_tile": false,
        "profile_link_color": "1DA1F2",
        "profile_sidebar_border_color": "C0DEED",
        "profile_sidebar_fill_color": "DDEEF6",
        "profile_text_color": "333333",
        "profile_use_background_image": true,
        "profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
        "profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
        "default_profile": true,
        "default_profile_image": false,
        "following": null,
        "follow_request_sent": null,
        "notifications": null
      },
      "geo": null,
      "coordinates": null,
      "place": null,
      "contributors": null,
      "is_quote_status": false,
      "quote_count": 0,
      "reply_count": 0,
      "retweet_count": 0,
      "favorite_count": 0,
      "entities": {
        "hashtags": [],
        "urls": [],
        "user_mentions": [
          {
            "screen_name": "R_Amsaveni",
            "name": "Amsaveni Rajasekar",
            "id": 973443365868994561,
            "id_str": "973443365868994561",
            "indices": [
              57,
              68
            ]
          }
        ],
        "symbols": []
      },
      "favorited": false,
      "retweeted": false,
      "filter_level": "low",
      "lang": "en",
      "timestamp_ms": "1523515032052"
    }
  ]
}

#16

That’s a regular Tweet, so there’s no specific “target” - the user mentioned is contained in the Tweet.


#17

Thanks for the reply @andypiper

what if I(subscribed user) mention three users where only one user is subscribed for webhook?

I will get the same response for two times right?

I need to identify the users who are all subscribed for webhook from the tweet_create_events response. So that only I can send a response back to the respected users like “you have mentioned by xxx”. I don’t want to send this response to everyone whose ID’s are available in url_mentions


#18

Hi @andypiper

What will be happened If an user revoke access for third-party application?

I would like to know whether the application be notified or not


#19

The application is not notified, but application tokens will be invalidated so the app will no longer be able to act on behalf of the user and will get Forbidden errors using the API. You can use the account/verify_credentials endpoint to check if tokens your app holds for a user are still valid.


#20

But when I revoke access for particular application from twitter I’m getting the following response

{"user_event":{"revoke":{"date_time":"2018-05-10T09:49:31+00:00","target":{"app_id":"4152140"},"source":{"user_id":"973443365868994561"}}}}

#21

That’s interesting - I’m not seeing that event generated in my own test application. Are you using the standard beta, or the enterprise offering?


#22

Standard beta