We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
hiweiwei
9 years agoExplorer | Level 3
Trouble migrating from API v1 to v2
Hello! I have this little code that can search dropbox file from slack,
I have been trying to migrate to API V2, but can't get it work.
Don't know what the problem is.
# encoding: utf-8
import time
import os
import json
from flask import Flask, request, render_template, url_for, json, jsonify
import csv
import dropbox
import requests
import sys
from slackclient import SlackClient
reload(sys)
sys.setdefaultencoding('utf-8')
app = Flask(__name__)
SLACK_WEBHOOK_SECRET = os.environ.get('SLACK_WEBHOOK_SECRET')
@app.route('/', methods=['POST'])
def index():
if request.method == 'POST' and request.form.get('token') == SLACK_WEBHOOK_SECRET:
username = request.form.get('user_name', 'null')
text = request.form.get('text', 'null')
channel = request.form.get('channel_name', 'null')
print channel
print username
print text
dbx = dropbox.Dropbox('dropboxtoken')
metadata, f = dbx.files_download('/inventory.csv')
out = open('inventory.csv', 'w')
out.write(f.content)
out.close()
with open('inventory.csv', 'rU') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for i, row in enumerate(readCSV):
for j, column in enumerate(row):
if text.replace("item:", "") in column:
print ' '.join(row)
payload = {"channel": "#"+channel, "username": "ROBOT-1", "text": "您查詢的是::point_down:\n"+' '.join(row), "icon_emoji": ":robot_face:"}
r = requests.post('webhookURL', data=json.dumps(payload))
print (r.url)
if __name__ == '__main__':
app.run(host='0.0.0.0')
4 Replies
- Greg-DB9 years ago
Dropbox Community Moderator
Can you share the error/output? Thanks in advance! - hiweiwei9 years agoExplorer | Level 3
Sorry for the late reply!
I host it on heroku, and it doesn't show error or crash.
- Greg-DB9 years ago
Dropbox Community Moderator
Being able to see the exception will be very important in writing/debugging the application, so I highly recommend referring to the Heroku documentation for information on how to retrieve the exception.
If you can't though, try reproducing the issue by running the app locally/in your development environment instead. - hiweiwei9 years agoExplorer | Level 3Ok! Thank you! I will try it.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!