I'm using python office365 library to access sharepoint documents. I don't know how to access file via API that have been shared with me by sharing link. I need to get this file content and if possible metadata (last modify date). Could anyone help?
The user that I'm using have no access to this sharepoint folder other than a sharing link to a single file.
I tried many variations of normal file access API, bot by hand and by office365 library. I couldnt find a way to access a file when I have only sharing link to it.
My sharing link looks like that:
https://[redacted].sharepoint.com/:x:/s/[redacted]/dir1/dir2/ESd0HkNNSbJMhQFavQsr9-4BNHC2rHSWsnbs3zRdjtZsC3g so there is not really a filename here and I cannot read via API content of any folder per se because I have an error Attempted to perform an unathorized operation.. Authentication goes fine (when i mistake password I get different error).
According to my research and testing, you can use the following Rest API to read file (get file content):
https://xxxx.sharepoint.com/sites/xxx/_api/web/GetFolderByServerRelativeUrl('/sites/xxx/Library_Name/Folder Name')/Files('Document.docx')/$value
If you want to get last modify date, you can use the following Rest API to get the Modified field:
https://xxxx.sharepoint.com/sites/xxx/_api/web/lists/getbytitle('test_library')/Items?$select=Modified
Related
I have dropbox filepicker in my project, once user select file i am receiving URL of the dropbox, now i want a content of that file using that URL in python.
here is the link which i received from dropbox picker : https://www.dropbox.com/s/ocissavtfvvdh2g/images.png?dl=0
I have checked this link https://sodocumentation.net/dropbox-api/topic/408/downloading-a-file, but it will ask for the path, but i don't have path of the file, i just have URL of the file
I just have to use 1 in dl querystring.
https://www.dropbox.com/s/ocissavtfvvdh2g/images.png?dl=1 like this
I would suggest you to use Dropbox API for your project. I made a similar project but using Google Drive API.
Check bellow
https://www.dropbox.com/developers/documentation/python#install
It sounds like you're using the Dropbox Chooser. If you just want direct access to the data of the selected file(s), you should use the "direct" link type.
Based on your sample link, I see that you're currently using the "preview" link type, which doesn't link directly to the file data, but rather a preview page.
Also, the sample code you linked to is for accessing files via the Dropbox API with an access token, not using a link returned by the Chooser, so it isn't relevant.
If you switch to the "direct" link type, you can use the returned link to directly access the file data just with an HTTP GET request, for four hours.
Alternatively, if you need access for longer than that, you can keep using the "preview" link type but modify the link as documented here.
I have sharepoint url where i can open and export that sharepoint list into excel. I want to automate that using python. i have tried many suggestions from online. but none of those are working.
i have tried below code to connect sharepoint
import requests
url= 'my sharepoint file path here'
r=requests.get(url,verify=False) #no username or password required
i am expecting the code should export sharepoint list data to new excel file.
I haven’t done this myself with code, but I believe it should work similar to what’s been done in SharePoint 2013: Export To Excel Using REST API
What they do there is actually using a link to a query that Excel can understand with parameters as the list id and view id. Since they use code within the browser it recognizes the content type (.iqy file) as something that should be opened in Excel. Don’t know how that would be when dont in Python though.
Another thing: Unless you have anonymous access turned on in your site, you need to authenticate the request to SharePoint.
I am in the process of setting up with Google Adwords API. They have a fantastic guide (https://developers.google.com/adwords/api/docs/guides/start), with the exception that one of the last steps is rather vague.
I have gotten to this step, pictured here (but from the link above)
I am instructed (for Python) to put the client ID and client secret into my own configuration file. All the other languages have specific files that were added to need to be edited (such as the PHP example below).
I have been working at this for the past 3 hours, and tried googling and youtubing and reading through every piece of documentation I can find. All of them just say "add the ID and secret to your config file." I have no idea what that means, or how to do it. I've gone into my python directory and found a file named "config.py", but have no idea how to add these credentials. There is a number of scripts on github (that Google links to), one of them for generating a refresh token, like I want. I have no idea how to implement this, though.
https://github.com/googleads/googleads-python-lib/tree/master/examples/adwords/authentication
Thank you in advance for any insight into adding credentials to my python config file or otherwise generating a refresh token.
I found the answer.
In short, the config file is in a directory that was not included in the instructions. It is advisable to download the entire "googleads-python-lib" directory versus just the directory "googlead".
https://github.com/googleads/googleads-python-lib
The config file (googleads.yaml) is within this "googleads-python-lib" directory. I unzipped it in my python2.7/site-packages. There are variables in this config file ready to take your authentication credentials.
I want to write a Python script that reads the names of the Facebook users who wrote a message on my Facebook Page.
I'm using the facebook-sdk Python library. The lines
graph = facebook.GraphAPI(page_access_token)
profile = graph.get_object(profile_id)
posts = graph.get_connections(profile['id'], 'feed')
print(posts['data'][0]['message'])
print(posts['data'][0]['from']['name'])
work fine when I use a short-lived access token retrieved by just copying it from the Graph API explorer.
But when I generate a never-expiring page access token (read here), there is an error in the last line where the Python script wants to retrieve the name. (KeyError: 'from')
So how do i set the right permissions? The access token has user_about_me, user_posts, read_page_mailboxes, manage_pages, publish_pages, public_profile permissions, but it still doesn't work. Maybe I did something wrong setting up the app I created to retrieve a new access token?
Or maybe this isn't a permissions issue after all? (See my previous question.)
You need to specify the fields you want to retrieve manually if you're using v2.4 or higher. Unfortunately this is not documented in the project you're using:
posts = graph.get_connections(profile['id'], 'feed', 'fields=id,message,from')
should work I guess according to https://github.com/pythonforfacebook/facebook-sdk/blob/master/facebook/init.py#L117
I'm looking for a way to sell someone a card at an event that will have a unique code that they will be able to use later in order to download a file (mp3, pdf, etc.) only one time and mask the true file location so a savvy person downloading the file won't be able to download the file more than once. It would be nice to host the file on Amazon S3 to save on bandwidth where our server is co-located.
My thought for the codes would be to pre-generate the unique codes that will get printed on the cards and store those in a database that could also have a field that stores the number of times the file was downloaded. This way we could set how many attempts we would allow the user for downloading the file.
The part that I need direction on is how do I hide/mask the original file location so people can't steal that url and then download the file as many times as they want. I've done Google searches and I'm either not searching using the right keywords or there aren't very many libraries or snippets out there already for this type of thing.
I'm guessing that I might be able to rig something up using django.views.static.serve that acts as a sort of proxy between the actual file and the user downloading the file. The only drawback to this method I would think is that I would need to use the actual web server and wouldn't be able to store the file on Amazon S3.
Any suggestions or thoughts are greatly appreciated.
Neat idea. However, I would warn against the single-download method, because there is no guarantee that their first download attempt will be successful. Perhaps use a time-expiration method instead?
But it is certainly possible to do this with Django. Here is an outline of the basic approach:
Set up a django url for serving these files
Use a GET parameter which is a unique string to identify which file to get.
Keep a database table which has a FileField for the file to download. This table maps the unique strings to the location of the file on the file system.
To serve the file as a download, set the response headers in the view like this:
(path is the location of the file to serve)
with open(path, 'rb') as f:
response = HttpResponse(f.read())
response['Content-Type'] = 'application/octet-stream';
response['Content-Disposition'] = 'attachment; filename="%s"' % 'insert_filename_here'
return response
Since we are using this Django page to serve the file, the user cannot find out the original file location.
You can just use something simple such as mod_xsendfile. This functionality is also available in other popular webservers such lighttpd or nginx.
It works like this: when enabled your application (e.g. a trivial PHP script) can send a special response header, causing the webserver to serve a static file.
If you want it to work with S3 you will need to handle each and every request this way, meaning the traffic will go through your site, from there to AWS, back to your site and back to the client. Does S3 support symbolic links / aliases? If so you might just redirect a valid user to one of the symbolic URLs and delete that symlink after a couple of hours.