有没有办法用PHP在我的SaaS网站中显示来自Gmail收件箱的电子邮件?
UPDATE:OP编辑了询问PHP客户端库的问题。
PHP Gmail谷歌客户端库可用,但仍处于测试阶段。关于如何使用Google API的代码片段在他们的Github存储库中,但Gmail API示例不可用。这个Gmail API定义文件是一个很好的开始。
你可以使用谷歌Gmail API。它有.NET、Java和Python的客户端库。引用自文档:
您的应用程序可以使用API添加Gmail功能,如:
- 阅读来自Gmail的邮件
- 发送电子邮件
- 修改应用于消息和线程的标签
- 搜索特定的消息和线程
关于如何按照快速入门指南使用API的示例:
#!/usr/bin/python
import httplib2
from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run
# Path to the client_secret.json file downloaded from the Developer Console
CLIENT_SECRET_FILE = 'client_secret.json'
# Check https://developers.google.com/gmail/api/auth/scopes for all available scopes
OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.readonly'
# Location of the credentials storage file
STORAGE = Storage('gmail.storage')
# Start the OAuth flow to retrieve credentials
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
http = httplib2.Http()
# Try to retrieve credentials from storage or run the flow to generate them
credentials = STORAGE.get()
if credentials is None or credentials.invalid:
credentials = run(flow, STORAGE, http=http)
# Authorize the httplib2.Http object with our credentials
http = credentials.authorize(http)
# Build the Gmail service from discovery
gmail_service = build('gmail', 'v1', http=http)
# Retrieve a page of threads
threads = gmail_service.users().threads().list(userId='me').execute()
# Print ID for each thread
if threads['threads']:
for thread in threads['threads']:
print 'Thread ID: %s' % (thread['id'])
有关更多详细信息,请参阅快速入门指南:https://developers.google.com/gmail/api/quickstart/quickstart-python
在这个问题上也有类似的问题。