Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add login method to parse space links #26

Closed
mirusu400 opened this issue Jan 2, 2022 · 4 comments · Fixed by #27
Closed

Add login method to parse space links #26

mirusu400 opened this issue Jan 2, 2022 · 4 comments · Fixed by #27
Assignees
Labels
enhancement New feature or request

Comments

@mirusu400
Copy link
Contributor

Is your feature request related to a problem? Please describe.

It seems that some user's space links are not parsed from UserTweets API.

When the user streams twitter spaces, twspace still has RuntimeError User is not live.

Describe the solution you'd like

https://github.com/Ryu1845/twspace-dl/blob/704b51438ca14487a58264fd966b6877961ee8f0/twspace_dl/TwspaceDL.py#L37

Add a login (or cookie) method / parameters instead of using UserTweets APIs.

Additional context
When we are on login, we can get space links from https://twitter.com/i/api/fleets/v1/avatar_content.

@mirusu400 mirusu400 added the enhancement New feature or request label Jan 2, 2022
@Ryu1845
Copy link
Collaborator

Ryu1845 commented Jan 2, 2022

That seems reasonable, I'll look into it asap

@mirusu400
Copy link
Contributor Author

import requests
headers = {
    "authorization": (
        "Bearer "
        "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs"
        "=1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
    ),
    "cookie": 'auth_token=456472d275c2e636c43c85b7705879693a0c9da8;'
}
user_id = "1081889494725361664"
r = requests.get(f"https://twitter.com/i/api/fleets/v1/avatar_content?user_ids={user_id}&only_spaces=true", headers=headers)

obj = r.json()
broadcast_id = obj["users"][user_id]["spaces"]["live_content"]["audiospace"]["broadcast_id"]
broadcast_title = obj["users"][user_id]["spaces"]["live_content"]["audiospace"]["title"]

print(f"Title: {broadcast_title}\tLink: https://twitter.com/i/spaces/{broadcast_id}")

""" JSON Example
{"users":{"1081889494725361664":{"spaces":{"live_content":{"audiospace":{"broadcast_id":"1BdxYwDXzqyGX","id":"","title":"아무나 ㄱ","state":"","creator_user_id":"","creator_twitter_user_id":1081889494725361664,"primary_admin_user_id":"","admin_user_ids":null,"pending_admin_user_ids":null,"admin_twitter_user_ids":[1081889494725361664],"pending_admin_twitter_user_ids":null,"max_admin_capacity":0,"max_guest_sessions":0,"conversation_controls":0,"created_at":null,"updated_at":null,"ended_at":null,"start":"2022-01-02T09:56:30.915552731Z","scheduled_start":null,"canceled_at":null,"guests":[{"user_id":"","session_uuid":"","twitter_user_id":1237181646652071936}],"copyright_violations":null,"is_locked":false,"is_employee_only":false,"rules":null,"topics":null,"is_muted":false,"is_space_creator_muted":false,"language":"ko","enable_server_audio_transcription":false,"is_space_available_for_replay":false,"replay_start_time":null,"is_trending":false,"vf_safety_level":0,"is_featured":false,"is_creator_top_host":false,"total_participating":1,"total_participating_public":0,"total_participated":10,"total_participated_public":0}},"participants":[1081889494725361664,1237181646652071936]}}},"refresh_delay_secs":30}
"""

Here are my sample snippet (from scratch), we only need auth_token and it can simply get from cookies.

Unfortunately, It seems that manual login method is a bit complicated.

@Ryu1845
Copy link
Collaborator

Ryu1845 commented Jan 2, 2022

Yeah I think I'll use a cookie file

@SD170
Copy link

SD170 commented Jun 7, 2023

Hey can you tell me auth_token here is the oAuth1 access secret right?
Or I'm missing something? Basically, I want to know, how can I get the authToken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants