cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trouble migrating from API v1 to v2

Trouble migrating from API v1 to v2

hiweiwei
Explorer | Level 3

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 4

Greg-DB
Dropbox Staff
Can you share the error/output? Thanks in advance!

hiweiwei
Explorer | Level 3

Sorry for the late reply!

I host it on heroku, and it doesn't show error or crash.

Greg-DB
Dropbox Staff
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.

hiweiwei
Explorer | Level 3
Ok! Thank you! I will try it.
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    hiweiwei Explorer | Level 3
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?