2011-02-24 49 views
2

我試圖上傳使用Python SDK中的圖片:GraphAPIError:(#324)需要上傳文件

代碼:

graph = facebook.GraphAPI(self.current_user.access_token) 
graph.put_object("me", "photos", name = "test", message = raw_picture_data) 

但我得到的錯誤"GraphAPIError: (#324) Requires upload file"。我不認爲它的權限問題,因爲我已經請求perms =「user_photos,friends_photos,publish_stream」。有誰知道這個錯誤意味着什麼以及如何解決它?

回答

0

也許你可以試試這個。 http://od-eon.com/blogs/tudor/facebook-photo-upload-google-app-engine/

我試圖用這個solved my problem,但我得到了這種反應 -
{ 「錯誤」:{ 「類型」: 「OAuthException」, 「消息」:「您必須使用https://經過時訪問令牌「}}

+0

我得到這個錯誤{ 「錯誤」:{ 「類型」: 「OAuthException」, 「消息」: 「(#324)需要上傳文件」}} – Adham 2011-03-05 16:32:32

4

我用這個庫來對圖像進行編碼:http://atlee.ca/software/poster/

添加這facebook.py:

from poster.encode import * 
from poster.streaminghttp import register_openers 

def put_photo(self, source, album_id=None, message=""): 
    object_id = album_id or "me" 

    register_openers() 
    content_type,body = multipart_encode([ ('message',message),('access_token',self.access_token),('source',source) ]) 

    req = urllib2.Request("https://graph.facebook.com/%s/photos" % object_id, content_type,body) 

    try: 
     data = urllib2.urlopen(req).read() 
    except urllib2.HTTPError as e: 
     data = e.read() 
    try: 
     response = _parse_json(data) 
     if response.get("error"): 
      raise GraphAPIError(response["error"].get("code", 1),response["error"]["message"]) 
    except ValueError: 
     response = data 

    return response 

電話與照片的功能文件中像對象:

graph = facebook.GraphAPI(access_token) 
photo = open("myphoto.bmp","rb") 
graph.put_photo(photo,"me","This is my brilliant photo") 

的put_photo方法已提交有人(我忘記是誰)所提出的功能添加到API,但直到我用海報來對圖像進行編碼它沒有爲我工作。

希望這會有所幫助。

0

剛和一個類似的錯誤作鬥爭。我沒有使用SDK,但只是一個POST的graphapi。對於我來說,這個錯誤發生在我沒有向發送到Facebook的「表單」中的文件上傳字段提供文件名時發生。 這是我的代碼(海報 - http://pypi.python.org/pypi/poster/0.8.1

from poster.encode import multipart_encode, MultipartParam 
url = 'https://graph.facebook.com/me/photos?access_token=%s'%model.facebook_token 
file_param = MultipartParam(name = 'source', 
          filename = 'photo.jpg', #this is crucial!!! 
          fileobj = blob_reader) #the blob reader is the fileobject for the file (with read() method) 
message_param = MultipartParam(name = 'message', 
           value = 'test message')         

datagen, headers = multipart_encode([file_param, 
            message_param]) 
from google.appengine.api import urlfetch 
result = urlfetch.fetch(url, 
       payload = ''.join(datagen), 
       headers = headers, 
       method = 'POST')  
return result.content        
相關問題