Update app permissions in my dropbox developer app - python

I have created an app in dropbox, however whenever I update the permissions for my app, and refresh the page, I lose all my updated permissions. Where do I save them?
Once I refresh the tab:
This is not just a visual glitch, as when I run the code
dbx = dropbox.Dropbox(DROPBOX_ACCESS_TOKEN)
def dropbox_list_files(path):
"""Return a Pandas dataframe of files in a given Dropbox folder path in the Apps directory.
"""
try:
files = dbx.files_list_folder(path).entries
files_list = []
for file in files:
if isinstance(file, dropbox.files.FileMetadata):
metadata = {
'name': file.name,
'path_display': file.path_display,
'client_modified': file.client_modified,
'server_modified': file.server_modified
}
files_list.append(metadata)
df = pd.DataFrame.from_records(files_list)
return df.sort_values(by='server_modified', ascending=False)
except Exception as e:
print('Error getting list of files from Dropbox: ' + str(e))
print(dropbox_list_files("/"))
I get the error:
Error getting list of files from Dropbox: BadInputError('**String of data**', 'Error in call to API function "files/list_folder": Your app is not permitted to access this endpoint because it does not have the required scope \'files.metadata.read\'. The owner of the app can enable the scope for the app using the Permissions tab on the App Console.')
How can I save my new permissions so that I don't get this error anymore?

There's a "Submit" button in the bar floating at the bottom of the page you need to use to save the changes you apply.

Related

connecting to sharepoint with python - Invalid URI: The Authority/Host could not be parsed.', "500 Server Error: Internal Server Error for url errors

I'm trying to connect to company sharepoint and use one of the example codes i found in this topic:
Accessing Microsoft Sharepoint files and data using Python
the first lines of the code worked, I got "Authenticated into sharepoint as:********"
after I used this and it worked also
####Function for extracting the file names of a folder in sharepoint###
###If you want to extract the folder names instead of file names, you have to change "sub_folders = folder.files" to "sub_folders = folder.folders" in the below function
global print_folder_contents
def print_folder_contents(ctx, folder_url_shrpt):
try:
folder = ctx.web.get_folder_by_server_relative_url(folder_url_shrpt)
fold_names = []
sub_folders = folder.files #Replace files with folders for getting list of folders
ctx.load(sub_folders)
ctx.execute_query()
for s_folder in sub_folders:
fold_names.append(s_folder.properties["Name"])
return fold_names
except Exception as e:
print('Problem printing out library contents: ', e)
Than I called the function to print the list of the elements with this code
# Call the function by giving your folder URL as input
filelist_shrpt=print_folder_contents(ctx,folder_url_shrpt)
#Print the list of files present in the folder
print(filelist_shrpt)
and I got this output:
"Problem printing out library contents: ('-1, System.UriFormatException', 'Invalid URI: The Authority/Host could not be parsed.', "500 Server Error: Internal Server Error for url: https://mycompany.sharepoint.com/sites/mysharepointpage/_api/Web/getFolderByServerRelativeUrl('https:%2F%2Fmycompany.sharepoint.com%2Fsites%2FKmysharepointpage%2FDocuments%2520partages%2FGeneral%2F')/Files")
None"
someone can help me with this issue?
You can try a virtual printer driver that has a bidirectional integration to SharePoint. Here is a link to the download https://www.microsoft.com/store/apps/9NZL8MWS3MLG and here is a quick video https://vimeo.com/manage/videos/515880976

How to create a folder in Team Drive with Google's Python Drive Client API?

I don't seem to find many articles on this. The tutorial from Google only shows creating folders in a regular Google Drive folder.
Below is my function and it fails with oogleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/drive/v3/files?alt=json returned "File not found: myteamdrivefolderid.". Details: "File not found: myteamdrivefolderid.">
My app is a Python desktop app and has already been authorized to have full Drive read/write scope.
def create_folder(service, name, parent_id=None, **kwargs):
# Create a folder on Drive, returns the newely created folders ID
body = {
'name': name,
'mimeType': "application/vnd.google-apps.folder"
}
if parent_id:
body['parents'] = [parent_id]
if 'teamDriveId' in kwargs:
body['teamDriveId'] = kwargs['teamDriveId']
folder = service.files().create(body=body).execute()
return folder['id']
I believe your goal and situation as follows.
You want to create new folder in the shared Drive using googleapis for python.
You have the permission for creating new folder in the shared Drive.
You have already been able to use Drive API.
Modification points:
In this case, please add supportsAllDrives to the query parameter.
It seems that teamDriveId is deprecated. Please use driveId. Ref
When above points are reflected to your script, it becomes as follows.
Modified script:
body = {
'name': name,
'mimeType': "application/vnd.google-apps.folder"
}
if parent_id:
body['parents'] = [parent_id]
if 'teamDriveId' in kwargs:
body['driveId'] = kwargs['teamDriveId'] # Modified
folder = service.files().create(body=body, supportsAllDrives=True).execute() # Modified
return folder['id']
Reference:
Files: create

How to open an SGF file with an external application in an android app?

I'm trying to open an SGF file (a format popular for storing go games) in an external app. My current code manages to fire up an app which then fails to load it by default. I can't seem to change this behaviour.
Using other apps to open the file I get inconsistent behaviour. The file browser says there is no app capable of opening sgf files and redirects me to the play store (regardless of which of the apps I subsequently install). However, the internet browser gives me a popup telling me to choose one of 2 suitable apps. I would like to have the same behaviour in my app, where the user can explicitly select the app to open it with.
My current code (which does seem to open an app, show a message 'failed to load' and quits, not hitting the exception):
file = self.files[self.file_ix]
if platform == "android":
from jnius import autoclass
Intent = autoclass("android.content.Intent")
Uri = autoclass('android.net.Uri')
PythonActivity = autoclass("org.renpy.android.PythonActivity")
try:
intent = Intent()
intent.setAction(Intent.ACTION_VIEW)
intent.setDataAndType(Uri.parse(file), "application/x-go-sgf")
PythonActivity.mActivity.startActivity(intent)
except Exception as e:
self.hint.text = f"No SGF Viewer found: {e}"
else:
os.system(f"xdg-open '{file}'")
How can I change it to get the popup with the choice of apps?

Create new folder with Onedrive API python

i have problem in creating folder with onedrive API 2.0
here is my code:
_folder = onedrivesdk.Folder()
_item = onedrivesdk.Item()
_item.name = new_folder_name
_item.folder = _folder
client.item(drive='me', path=location).children.add(_item)
it works on windows normally but not on osx
error occur in onedrive sdk children_collection.py
entity = Item(json.loads(self.send(entity).content))
on this code Item means 'onedrivesdk.model.item.Item'
but sdk define it as global value and return error like this
error when i create folder
please help me

Python & gdata within Django app: "POST method does not support concurrency"

I am trying to use gdata within a Django app to create a directory in my google drive account. This is the code written within my Django view:
def root(request):
from req_info import email, password
from gdata.docs.service import DocsService
print "Creating folder........"
folder_name = '2015-Q1'
service_client = DocsService(source='spreadsheet create')
service_client.ClientLogin(email, password)
folder = service_client.CreateFolder(folder_name)
Authentication occurs without issue, but that last line of code triggers the following error:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.7.7
Exception Type: RequestError
Exception Value: {'status': 501, 'body': 'POST method does not support concurrency', 'reason': 'Not Implemented'}
I am using the following software:
Python 2.7.8
Django 1.7.7
PyCharm 4.0.5
gdata 2.0.18
google-api-python-client 1.4.0 (not sure if relevant)
[many other packages that I'm not sure are relevant]
What's frustrating is that the exact same code (see below) functions perfectly when I run it in its own, standalone file (not within a Django view).
from req_info import email, password
from gdata.docs.service import DocsService
print "Creating folder........"
folder_name = '2015-Q1'
service_client = DocsService(source='spreadsheet create')
service_client.ClientLogin(email, password)
folder = service_client.CreateFolder(folder_name)
I run this working code in the same virtual environment and the same PyCharm project as the code that produced the error. I have tried putting the code within a function in a separate file, and then having the Django view call that function, but the error persists.
I would like to get this code working within my Django app.
I don't recall if I got this to work within a Django view, but because Google has since required the use of Oauth 2.0, I had to rework this code anyways. I think the error had something to do with my simultaneous use of two different packages/clients to access Google Drive.
Here is how I ended up creating the folder using the google-api-python-client package:
from google_api import get_drive_service_obj, get_file_key_if_exists, insert_folder
def create_ss():
drive_client, credentials = get_drive_service_obj()
# creating folder if it does not exist
folder = get_file_key_if_exists(drive_client, 'foldername')
if folder: # if folder exists
print 'Folder "' + folder_name + '" already exists.'
else: # if folder doesn't exist
print 'Creating folder........"' + folder_name + '".'
folder = insert_folder(drive_client, folder_name)
After this code, I used a forked version (currently beta) of sheetsync to copy my template spreadsheet and populate the new file with my data. I then had to import sheetsync after the code above to avoid the "concurrency" error. (I could post the code involving sheetsync here too if folks want, but for now, I don't want to get too far off topic.)

Categories