• Obl

    As you can see in my already posted Code, I already use one of the right scopes. I also tried the other two scopes, still Errorcode 403. I also checked the other URLs in Google OAuth Playground, they are also correct.

    posted in Pythonista read more
  • Obl

    I know the playlistId and also the videoId. The are definitive correct and not the problem.

    posted in Pythonista read more
  • Obl

    Yes, it is my own playlist. On the Google site it is possible to add a video to the playlist. But the site is not the same as the code used.

    posted in Pythonista read more
  • Obl

    I tried your approach, but with the same result: forbidden (403) playlistItemsNotAccessible.

    I found the scope in this site: https://developers.google.com/youtube/v3/docs/playlistItems/insert
    There is also some Python Code, but it's also not working in Pythonista.

    posted in Pythonista read more
  • Obl

    Finally I found some time to try your approach and voila! it starts to work! Now I am able to connect to the server and get the tokens, everything works until I want to add the video to the playlist. Then I get a

    forbidden (403) playlistItemsNotAccessible
    

    I will post my (modified) code here once again:

    def playlistItem_insert(videoId, key):
    with open(CLIENT_SECRETS_FILE, 'r') as file_obj:
       client_credentials = json.load(file_obj)
    private_key_pkcs8_pem = client_credentials['private_key']
    signer = _pure_python_crypt.RsaSigner.from_string(private_key_pkcs8_pem)
    
    header = {'typ': 'JWT', 'alg': 'RS256'}
    now = int(time.time())
    payload = {
           'aud': 'https://www.googleapis.com/oauth2/v4/token',
           'scope': 'https://www.googleapis.com/auth/youtube.force-ssl',
           'iat': now,
           'exp': now + 3600, # 1 hour in seconds
           'iss': service_account_email_address
    }
    segments = [
           _helpers._urlsafe_b64encode(_helpers._json_encode(header)),
           _helpers._urlsafe_b64encode(_helpers._json_encode(payload)),
    ]
    signing_input = b'.'.join(segments)
    signature = signer.sign(signing_input)
    segments.append(_helpers._urlsafe_b64encode(signature))
    claim = b'.'.join(segments)
    
    post_data = {
           'grant_type':'urn:ietf:params:oauth:grant-type:jwt-bearer',
           'assertion':claim
    }
    req = requests.post('https://www.googleapis.com/oauth2/v4/token', post_data)
    resp = req.json()
    access_token = resp['access_token']
    auth_header = {
           'Authorization':'Bearer ' + access_token
    }
    
    # Use the header in service requests, e.g.
    d={'snippet': { 
    'playlistId': PLAYLIST_ID, 'resourceId': { 
    'kind': 'youtube#video', 
    'videoId': videoId}
    }
    }
    req = requests.post('https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&key='+key, json=d, headers = auth_header)
    req.raise_for_status()
    return req.status_code
    

    Parameters are all available. The problem occurs in line req = requests.post(...)
    Maybe someone has better eyes than me...

    posted in Pythonista read more
  • Obl

    I wrote a little script that gets me a video-Id from Youtube that I want to add to a playlist. Now I tried to execute the following:

    #add to playlist
    url_post='https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&key='+key
    data={"snippet": {
        "playlistId": playListId,
        "resourceId": {
            "videoId": videoId,
            "kind": "youtube#video"
            }
        }
    }
    data_json=json.dumps(data)
    response=requests.post(url_post, data=data_json)
    

    I got a 401-Unauthorized and read the following link https://developers.google.com/youtube/v3/docs/playlistItems/insert where is mentioned, that I have to authenticate with OAuth. So I created some OAuth 2.0-Client-IDs in https://console.developers.google.com.
    But now I don't have any clue how to use OAuth to get this working in Pythonista.
    So how can I authenticate at Youtube to add a Video to my playlist?

    posted in Pythonista read more
  • Obl

    Ok thanks for the workaround! I will try it.

    posted in Pythonista read more
  • Obl

    I wrote a little script in Pythonista that reads the song from my favorite radio station. This combined with a (Apple) Workflow adds this title to a playlist.
    Now my problem is, that I want to start the Workflow script as Today Widget. But if I do so, Pythonista is always opened and the the Workflow script stops until I go back from Pythonista.
    Is there any way to run Pythonista-Script in background when executing inside a Workflow? It's not really helpful when I have to interact each time.
    Thanks already in advance!

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!