codexerOO
codexerOO

Reputation: 145

Search for a file or folder from google drive api via the name of the file/folder?

I am trying to make a function that can search for a file/folder. If the file/folder exists then it will return the id else will return null from the drive in PHP, but every time I do this it shows that there is some error in q.

An error occurred: {
    "error": {
        "errors": [
            {
                "domain": "global",
                "reason": "invalid",
                "message": "Invalid Value",
                "locationType": "parameter",
                "location": "q"
            }
        ],
        "code": 400,
        "message": "Invalid Value"
    }
}

The query is:-

//testing-folder-of-api is the name of the folder
mimeType=application/vnd.google-apps.folder and name='testing-folder-of-api'

I also tried with changing it like:

  1. mimeType!=application/vnd.google-apps.folder if not a file
  2. name contains 'test.txt' and title='test.txt' for searching it by name.

The solution that I found was that to loop through all the files and check the name individually using a loop which took to much time.

Can someone plz show me how to do it. Please!!

Upvotes: 1

Views: 798

Answers (1)

Iamblichus
Iamblichus

Reputation: 19309

Issue:

You should add single quotes around 'application/vnd.google-apps.folder', as mentioned at File-specific query terms:

mimeType: MIME type of the file. Surround with single quotes '.

Solution:

mimeType='application/vnd.google-apps.folder' and name='testing-folder-of-api'

Upvotes: 1

Related Questions