theprnce / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

Perform Google Apps Domain-wide Delegation of Authority #255

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
[Use this form for both apiclient and oauth2client issues]

What steps will reproduce the problem?
1. Followed the python example: 
https://developers.google.com/drive/delegation#delegate_domain-wide_authority_to
_your_service_account
2. Tried to upload a file on a user's behalf and returning error message.
3.

What is the expected output? What do you see instead?
Expect the file to upload ok but I am instead receiving:
apiclient.errors.HttpError: <HttpError 401 when requesting 
https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&alt=json 
returned "Invalid Credentials">

What version of the product are you using? On what operating system?
Python 2.7 google-api-python-client 1.1 Linux Mint 14

Please provide any additional information below.

import httplib2
import pprint
import sys
import gflags

from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
from apiclient.http import MediaFileUpload

FLAGS = gflags.FLAGS

gflags.DEFINE_enum('logging_level', 'ERROR',
    ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
    'Set the level of logging detail.')

SERVICE_ACCOUNT_EMAIL = 'mynumber@developer.gserviceaccount.com'
SERVICE_ACCOUNT_PKCS12_FILE_PATH = 'key.p12'

def createDriveService(user_email):
    f = file(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'rb')
    key = f.read()
    f.close()

    credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL, key,
      scope='https://www.googleapis.com/auth/drive', prn=user_email)
    http = httplib2.Http()
    http = credentials.authorize(http)

    return build('drive', 'v2', http=http)

test = createDriveService('user@mydomain.example')
FILENAME = 'document.txt'
media_body = MediaFileUpload(FILENAME, mimetype='text/plain')
body = {
        'title': 'My document',
        'description': 'A test document',
        'mimeType': 'text/plain'
        }
testfile = test.files().insert(body=body, media_body=media_body).execute()

Original issue reported on code.google.com by g.ll...@keele.ac.uk on 27 Mar 2013 at 2:51

GoogleCodeExporter commented 9 years ago
Try instead to use

sub=user_email

instead of

prn=user_email

I'm not sure this will fix anything, but the spec has been finalized by the RFC 
and so Google has updated our implementation to the final spec.

Original comment by dhermes@google.com on 27 Mar 2013 at 2:57

GoogleCodeExporter commented 9 years ago
Hi

Just tried your suggestion, but it is still returning the same error.

Thanks

Original comment by g.ll...@keele.ac.uk on 27 Mar 2013 at 3:00

GoogleCodeExporter commented 9 years ago
Hi I've resolved the issue.

I had moved my test account to an Org unit that had Google Drive disabled(doh!).

Thanks

Original comment by g.ll...@keele.ac.uk on 27 Mar 2013 at 3:58

GoogleCodeExporter commented 9 years ago

Original comment by dhermes@google.com on 27 Mar 2013 at 4:17