How to identify webhook subscribed user from the response payload


#1

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 twitter. How do I identify the user to whom the response has been received.

Here I have attached response for your reference

{
"tweet_create_events":[
{
"created_at":"Tue Apr 10 05:08:57 +0000 2018",
"id":983572522619711488,
"id_str":"983572522619711488",
"text":"@Sample2511 mention tweet 2",
"source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e",
"truncated":false,
"in_reply_to_status_id":null,
"in_reply_to_status_id_str":null,
"in_reply_to_user_id":949259913468903427,
"in_reply_to_user_id_str":"949259913468903427",
"in_reply_to_screen_name":"Sample2511",
"user":{
"id":973443365868994561,
"id_str":"973443365868994561",
"name":"Amsaveni Rajasekar",
"screen_name":"R_Amsaveni",
"location":null,
"url":null,
"description":null,
"translator_type":"none",
"protected":false,
"verified":false,
"followers_count":0,
"friends_count":0,
"listed_count":0,
"favourites_count":2,
"statuses_count":20,
"created_at":"Tue Mar 13 06:19:18 +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":"Sample2511",
"name":"sample",
"id":949259913468903427,
"id_str":"949259913468903427",
"indices":[
0,
11
]
}
],
"symbols":[
]
},
"favorited":false,
"retweeted":false,
"filter_level":"low",
"lang":"fr",
"timestamp_ms":"1523336937943"
}
]
}

Thanks in advance


#2

@Sample2511

Can you help me with registering webhook url, Twitter staff is not helping any more.

I am getting an error while registering url:

{
    "errors": [
        {
            "code": 261,
            "message": "Application cannot perform write actions. Contact Twitter Platform Operations through https://support.twitter.com/forms/platform."
        }
    ]
}

I tried all the possible solutions but didn’t get sort out this.

Thank in advanced


#4

@Sample2511 Thanks for the reply

My application has below permissions

Read, Write and Access direct messages

I also get Account activity approval email from twitter to user Beta application.

But still get same error

My webhook url is below:

https://api.twitter.com/1.1/account_activity/all/:env-beta/webhooks.json?url=https://tweester.in/tweetcafe/webhook/twitter/getTweet.php


#5

@vinodsaini
env_name should be like this(env-beta) in your webhook url

https://api.twitter.com/1.1/account_activity/all/env-beta/webhooks.json?

not (:env-beta)


#6

Used above url but still getting same error.

I am using php to perform this. code is below, please let me know where I am doing mistake.

$url =  urlencode('https://tweester.in/tweetcafe/webhook/twitter/getTweet.php');
$webhooksUrl = 'https://api.twitter.com/1.1/account_activity/all/env-beta/webhooks.json?url=' . $url;
$token = 'my_access_token';
$headers = array(
	'Content-Type:application/x-www-form-urlencoded',	
	'authorization: Bearer ' . $token,
);
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $webhooksUrl); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
$result  = curl_exec($ch); 
curl_close($ch); 
echo '<pre>';print_r($result);exit;

#7

I am using app-user auth instead of app-only oauth and it’s working fine for me
check this link for your reference
https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference/aaa-standard-all


#8

How do I get app-user auth using api?


#9

use the following information in the header along with Content-Type and Content-Length

requestHeader = "OAuth " + "oauth_consumer_key=\"" + URLEncoder.encode(consumerKey, "UTF-8") + "\"" + ", oauth_nonce=\"" + URLEncoder.encode(String.valueOf(millis), "UTF-8") + "\"" + ", oauth_signature=\"" + URLEncoder.encode(signature, "UTF-8") + "\"" + ", oauth_signature_method=\"" + URLEncoder.encode("HMAC-SHA1", "UTF-8") + "\"" + ", oauth_timestamp=\"" + URLEncoder.encode(String.valueOf(time), "UTF-8") + "\"" + ",oauth_token=\"" + URLEncoder.encode(oauthToken, "UTF-8") + "\"" + ", oauth_version=\"" + URLEncoder.encode("1.0", "UTF-8") + "\"";

#10

@Sample2511

Can you send in the php format, Its look like very complex perameters

Thank you