简体   繁体   English

Dropbox API-PHP-在网站中显示图片文件

[英]Dropbox api - php - display image file in website

This might sound trivial for some of you, but I need to be sure... 对于某些人来说,这听起来似乎微不足道,但是我需要确定...

I simply need to use dropbox for 2 things : 我只需要使用dropbox做两件事:

  • upload image files via php from my web server with the possibility of creating folder (as I would do on a normal web server) or sync folders from my web server to dropbox via rsync; 通过php从我的Web服务器上传图像文件,并可以创建文件夹(就像在普通Web服务器上那样),或者通过rsync将我的Web服务器中的文件夹同步到保管箱;

  • display these image files in a web page 在网页中显示这些图像文件

I have downloaded the api sdk, then run into the 64bit exception error, then invalid redirect-uri... 我已经下载了api sdk,然后遇到了64位异常错误,然后遇到无效的redirect-uri ...

So I would really appreciate if someone can reply to my 2 questions above and point me to a good example to just do that. 因此,如果有人可以回答我上面的两个问题,并为我指出一个很好的例子,我将非常感激。

I solved it in another way. 我用另一种方式解决了。 Rather than displaying the raw-file I use the API to generate Direct Download Link. 我没有显示原始文件,而是使用API​​来生成直接下载链接。 This will give me a weblink that I then modify by adding a "raw=1" and subsitute the "dl=0" with "dl=1". 这将给我一个网络链接,然后通过添加“ raw = 1”并用“ dl = 1”替换“ dl = 0”来进行修改。 This new link than then be used as the source for a normal html image. 然后,此新链接将用作普通html图像的源。

As per above suggestions 根据以上建议

import dropbox
import json
import httplib, urllib, base64

access_token='your token'
client = dropbox.client.DropboxClient(access_token)
url = client.share('test.jpg',short_url=False)
imageurl = url['url'].replace("dl=0","raw=1")

body = {
"url":imageurl
}
print json.dumps(body) 

headers = {
# Request headers
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '00759a20e705487a91e4db51b80bdfa7',
 }

params = urllib.urlencode({
}) 

try:
conn = httplib.HTTPSConnection('api.projectoxford.ai')
conn.request("POST", "/emotion/v1.0/recognize?%s" % params,json.dumps(body),        headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM