cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Trouble migrating from API v1 to v2

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
Highlighted

Re: Trouble migrating from API v1 to v2

Dropboxer
Dropboxer
Can you share the error/output? Thanks in advance!
Highlighted

Re: Trouble migrating from API v1 to v2

Explorer | Level 3

Sorry for the late reply!

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

Highlighted

Re: Trouble migrating from API v1 to v2

Dropboxer
Dropboxer
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.
Highlighted

Re: Trouble migrating from API v1 to v2

Explorer | Level 3
Ok! Thank you! I will try it.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?