2016-07-19 1 views
0

니펫을했습니다GmailUserSocialAuth 전자 메일 메시지는 빈 메시지를 반환하지만 내가 가진 요청을 받고, 파이썬에서의 Gmail API 함께 일하고 있어요

gmail_auth = GmailUserSocialAuth.objects.filter(uid='...')[0] 
response = gmail_auth.request('get', '...') 
data = response.json() 

response - gmail_auth.request('get', '/%s' % data['messages'][0]['id'] 
message = response.json() 

내가 메시지를 인쇄 할 때, 나는 모든 대형 큰 개체를 얻을 수 분야 등. 메시지 중 하나와 함께, 내가이 응답을 얻을 : 어쨌든

{ 
    ... # a lot of fields 
    u'sizeEstimate': 10100, 
    'html_body': '', 
    'decoded_body': '', 
    u'snippet': u'Hi —, <content of email>. On Jun 30, 2016..., Ofek Gila <...> wrote: <content of previous email in thread>.', 
} 

을, 문제는 내가이 코드에서 나타나기 때문에 이메일이 작성된 알고 있지만, 그것은 메시지 개체에 다른 곳에서는 나타나지 않는다는 것입니다 .

어떤 일이 벌어 지는지 알고 싶습니다.

미리 감사드립니다.

답변

1

시도는 Python sample code에 명시된대로이 방법을 얻을 사용할 수 있습니다. 또한 추가 통찰력이 SO threadthis one을 확인 할 수 있습니다

def GetMimeMessage(service, user_id, msg_id): 
    """Get a Message and use it to create a MIME Message. 

    Args: 
    service: Authorized Gmail API service instance. 
    user_id: User's email address. The special value "me" 
    can be used to indicate the authenticated user. 
    msg_id: The ID of the Message required. 

    Returns: 
    A MIME Message, consisting of data from Message. 
    """ 
    try: 
    message = service.users().messages().get(userId=user_id, id=msg_id, 
              format='raw').execute() 
    print 'Message snippet: %s' % message['snippet'] 
    msg_str = base64.urlsafe_b64decode(message['raw'].encode('ASCII')) 
    mime_msg = email.message_from_string(msg_str) 
    return mime_msg 
    except errors.HttpError, error: 
    print 'An error occurred: %s' % error 

: 는 여기에 조각입니다.

+0

의견에 감사드립니다. 꼭 확인해 보겠습니다. –

+0

이게 도움이되지 않는 것 같아서, 나에게 똑같은 문제가 생겼다. 나는 대부분의 메시지 (하나만 제외하고)가 잘 작동한다는 것을 알고있다. 한 가지 예는 메시지가 존재하지 않지만 메시지를 보여주는 단편입니다. 그 원인이 무엇이겠습니까? 당신의 도움을 주셔서 감사합니다! –