Search code examples
pythongoogle-apigspread

Is there a way to specify exact path to "client_secret.json"


Im new to this stuff and i really don't know what to do now, i need to be able to type exact path to "client_secret.json" file but in every tutorial i saw it only uses file name that is in same directory, but mine isn't.

creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)


Solution

  • Yes, anywhere that accepts a filename will accept an absolute or relative pathway. You are talking about relative pathways (being in the same directory), and you can use these like:

    creds = ServiceAccountCredentials.from_json_keyfile_name('../client_secret.json', scope)
    

    Where the ../ specifies to go up one folder and then look for your file. Additionally you could use an absolute pathway like:

    creds = ServiceAccountCredentials.from_json_keyfile_name('C:\\Users\\myUser\\Desktop\\client_secret.json', scope)
    

    It's typically recommended to use relative pathways though, because that enables you to move your entire project folder to another place/drive without breaking all your links.

    Relative pathways can also navigate up and down the tree like:

    creds = ServiceAccountCredentials.from_json_keyfile_name('../../../SomeFolder/SubFolder/client_secret.json', scope)