Well, I’m trying to fetch multiple list.fields for the /2/users/:id/owned_lists endpoint. Calling the following endpoint https://api.twitter.com/2/users/79765753/owned_lists?expansions=owner_id&list.fields=follower_count&user.fields=created_at with a signature based on the signature base string
GET&https%3A%2F%2Fapi.twitter.com%2F2%2Fusers%2F79765753%2Fowned_lists&expansions%3Downer_id%26list.fields%3Dfollower_count%26oauth_consumer_key%3D__hidden__%26oauth_nonce%3Dkzji95O2Kt5cUEQpMwyuD7HkyGkks697%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1639245260%26oauth_token%3D__hidden__%26oauth_version%3D1.0%26user.fields%3Dcreated_at
I get the following response:
{"data":[{"follower_count":0,"id":"1467490425426558976","name":"IT related","owner_id":"79765753"}],"includes":{"users":[{"name":"Yurii Nekrasov","username":"driversti","created_at":"2009-10-04T16:15:34.000Z","id":"79765753"}]},"meta":{"result_count":1}}
Next, I want to add an additional parameter to the list.fields key: member_count.
The signature base string:
GET&https%3A%2F%2Fapi.twitter.com%2F2%2Fusers%2F79765753%2Fowned_lists&expansions%3Downer_id%26list.fields%3Dfollower_count%2Cmember_count%26oauth_consumer_key%3D__hidden__%26oauth_nonce%3DTWXtWHjilm8PGQ8O6HiiOhQ4Ot60VTun%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1639245452%26oauth_token%3D__hidden__%26oauth_version%3D1.0%26user.fields%3Dcreated_at
the url: https://api.twitter.com/2/users/79765753/owned_lists?expansions=owner_id&list.fields=follower_count,member_count&user.fields=created_at
The result is 401 Unauthorized. What I’m doing wrong?
What language / library are you coding in? Is there any reason why one of these doesn’t work for you? Twitter API v2 tools & libraries | Docs | Twitter Developer Platform usually it’s a problem with encoding the , comma in the url but it looks like you have it encoded correctly. I can’t spot exactly what could be wrong on first look anyway.
I use Java with no 3rd-party libraries. I wanted to paste a gist with the example of how I perform the encoding, signing and calling the API, but it is not allowed 
How can I share the code?
UPD. You may find my code in the post below.
Is there any restrictions in your environment that prevent you from using a library? I would not implement any of this myself, a generic oAuth library like scribe should work: GitHub - scribejava/scribejava: Simple OAuth library for Java
The only restriction is that I want to do this by myself. Clean, pure, and the only endpoints I need for my purposes.
Everything works except when I use more than one parameter for either user.fields or list.fields. I was hoping I’ll find here people who can point my mistakes if they are present 
Thank you for the library suggestion, but I’d prefer to implement everything on my own 
1 Like
system
closed
#7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.