We Want to Hear From You! What Do You Want to See on the Community? Tell us here!

Forum Discussion

hiweiwei's avatar
hiweiwei
Explorer | Level 3
8 years ago

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-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago
    Can you share the error/output? Thanks in advance!
  • hiweiwei's avatar
    hiweiwei
    Explorer | Level 3
    8 years ago

    Sorry for the late reply!

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

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago
    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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 2 hours ago
410 Following

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 or Facebook.

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!