2013-12-17 21 views
1

我的問題與moment.insert from python code非常相似,但Fausto已經設法比我更進一步,所以我現在無法應用該答案。從python插入g +

我的代碼看起來是這樣的,我的問題是「我怎麼上傳到我的G +個人資料」

user = '[email protected]######.com' 
key = open(keyFile, 'r').read() 
credentials = SignedJwtAssertionCredentials(
    '#########@developer.gserviceaccount.com', 
    key, 
    scope='https://www.googleapis.com/auth/plus.login', 
    sub=user) 
http = httplib2.Http() 
http = credentials.authorize(http) 

service = build(serviceName='plus', version='v1', http=http) 

# Not really required here but these calls demonstrate that we are authenticated 
searchResults = service.people().search(query='AlistairWarner').execute() 
listMoments = service.moments().list(userId='me', collection='vault').execute() 

moment = { "type" : "http://schemas.google.com/AddActivity", 
      "target" : { 
        "id" : "target-id-1", 
        "type" : "http://schemas.google.com/AddActivity", 
        "name" : "The Google+ Platform", 
        "description" : "A page that describes just how awesome Google+ is!", 
        "image" : "https://developers.google.com/+/plugins/snippet/examples/thing.png" 
      } 
    } 

# This call fails with a "401 Unauthorized" error 
insertResults = service.moments().insert(userId='me', collection='vault', body=moment).execute() 

只是爲了記錄我已確認我已正確委派域範圍內的權力,我的服務說明了必要的範圍 - 儘管我不認爲這實際上是授權問題本身,因爲列表調用正在工作。我也證實,我的「應用程序」出現在我的g +個人資料下的應用程序中,正如囚徒在迴應福斯托的問題時所提到的(以上引用)。

看着API reference page它警告你會得到我看到的401錯誤。它和StackOverflow上的其他帖子(我會給ref但不允許),說你需要添加data-requestvisibleaction(再次,不能給ref)屬性,但我很努力地看到相關性他們描述的登錄按鈕將其附加到我的代碼中 - 沒有UI,我只是從命令行運行它。所以,requestvisibleaction似乎是最好的候選人,我只是不知道如何將它轉換成我可以在這裏使用的東西。

有沒有人有線索如何得到這個工作?

回答

0

您需要將此添加爲您的OAuth請求憑據的一部分。所以它可能看起來像

credentials = SignedJwtAssertionCredentials(
    '#########@developer.gserviceaccount.com', 
    key, 
    scope='https://www.googleapis.com/auth/plus.login', 
    requestvisibleactions='http://schemas.google.com/AddActivity', 
    sub=user) 
+0

試過 - 沒有區別,仍然得到401「未經授權」 – JoeWarner