Is there any way to show e-mails from Gmail inbox in my SaaS website in PHP?
1条回答 默认 最新
- dongxingguo1978 2014-11-11 03:50关注
UPDATE: The OP edited the question asking for PHP client library.
The PHP Gmail Google Client Library is available but it is still in beta. The code snippets on how to use Google API are in their Github Repository but the Gmail API example is not available. This Gmail API definition file is a good place to get started.
You can use the Google Gmail API. It has client libraries in .NET, Java and Python. Cite from docs:
your app can use the API to add Gmail features like:
- Read messages from Gmail
- Send email messages
- Modify the labels applied to messages and threads
- Search for specific messages and threads
An example on how to use the API as per their quick start guide:
#!/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'])
For more details, refer to the quick start guide: https://developers.google.com/gmail/api/quickstart/quickstart-python
There's a similar question on this matter.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 chaquopy python 安卓
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 有没有帮写代码做实验仿真的
- ¥15 報錯:Person is not mapped,如何解決?
- ¥30 vmware exsi重置后登不上
- ¥15 易盾点选的cb参数怎么解啊
- ¥15 MATLAB运行显示错误,如何解决?
- ¥15 c++头文件不能识别CDialog
- ¥15 Excel发现不可读取的内容
- ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题