Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

Get Shares, Subs Gained/Lost using Youtube Analytics + Python Request

TLDR: I want to get shares count of a video, subs gained/lost of a channel.

Details..

what I have tried:

using https://www.googleapis.com/youtube/v3/ and guide from https://developers.google.com/youtube/v3/docs , I can get channel information (name, desc, view count, subs count, video count) and video information (name, desc, view count, like/dislike count, favorite, comment count)

import json
import requests

BASE_URL = 'https://www.googleapis.com/youtube/v3/'
API_KEY = 'aaabbbbccc' # replace with your API key
CHANNEL_ID = 'aaabbbccc' # replace with a channel ID
VIDEO_ID = 'aaabbbccc'  # replace with a video ID

def get_video_info(v_id):
    data = {
        "part": 'snippet,statistics',
        "id": v_id,
        "key": API_KEY
    }
    clients_response = requests.get(BASE_URL + "videos", params=data)
    data_dict = {}
    if clients_response.status_code == 200:
        x = json.loads(clients_response.content.decode())
        for j in x["items"]:
            data_dict = {
                "videoID": j["id"],
                "videoURL": "https://www.youtube.com/watch?v=" + j["id"],
                "publishedAt": j["snippet"]["publishedAt"],
                "channelID": j["snippet"]["channelId"],
                "videoName": j["snippet"]["title"],
                "videoDesc": j["snippet"]["description"],
                "viewCount": j["statistics"]["viewCount"],
                "likeCount": j["statistics"]["likeCount"],
                "dislikeCount": j["statistics"]["dislikeCount"],
                "favoriteCount": j["statistics"]["favoriteCount"],
                #"commentCount": j["statistics"]["commentCount"],
            }
    return data_dict

def get_channel_info(c_id):
    data = {
        #"part": 'snippet,statistics',
        "part": 'snippet,contentDetails,statistics,status',
        #"part": 'auditDetails,brandingSettings,contentDetails,contentOwnerDetails,id,localizations,snippet,statistics,status,topicDetails',
        "id": c_id,
        "key": API_KEY
    }
    clients_response = requests.get(BASE_URL + "channels", params=data)
    clean_list = []
    if clients_response.status_code == 200:
        x = json.loads(clients_response.content.decode())
        for j in x["items"]:
            data_dict = {
                "channelID": j["id"],
                "channelURL": "https://www.youtube.com/channel/" + j["id"],
                "channelName": j["snippet"]["title"],
                "channelDesc": j["snippet"]["description"],
                "viewCount": j["statistics"]["viewCount"],
                "subscriberCount": j["statistics"]["subscriberCount"],
                "videoCount": j["statistics"]["videoCount"],
            }
            clean_list.append(data_dict)
    return clean_list

video_info = get_video_info(VIDEO_ID)
channel_info = get_channel_info(CHANNEL_ID)

BUT, I still couldnt get video shares, subs gained/lost. so I did some readings, and found these 2:

#1 Likes and Dislike count for weekly data from YouTube Data API

and

#2 Youtube API returning more views than is listed on native

is there a way to use standard python get request to get the video shares, subs gained/lost? without having to use youtube api (that use flow, flask, scopes, client secret json --> cause I also tried this and error msg indicate something about active HTTP request is needed)

I feel like this url could be a help, but not sure how to break it down https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel==UCaGKtfnhSkDsIbcyVVUOL6A&start-date=2017-06-27&end-date=2017-06-27&metrics=views,comments,likes,dislikes,shares,estimatedMinutesWatched,averageViewDuration,averageViewPercentage,annotationClickThroughRate,annotationCloseRate,subscribersGained,subscribersLost&dimensions=day&filters=video==qstWdXxFmcU

I have tried changing the channel ID, date start/to, and video ID.

coming out into the community for help means I am super desperate..

clues and help are very much appreciated. thank you.

question from:https://stackoverflow.com/questions/65928189/get-shares-subs-gained-lost-using-youtube-analytics-python-request

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...