Недавно я реализовал API Graph, чтобы:
Создать в общей папке различные каталоги с такими именами => "uc_123455";
в каждой созданной папке API загружает в него PDF-файлы.
Проблема:
Все запускается нормально, но через некоторое время просто перестает создавать папку, всего в ней почти Необходимо создать 2323 папки и прекратить создание после 1000.
Код работает следующим образом:
Сначала он получает
Код: Выделить всё
access_tokenКод: Выделить всё
$this->graph = new Graph();
$this->graph->setAccessToken($this->accessToken);
$this->directory_id = $this->fetchDirectoryId($this->graph);
First it create the name based on what part is of the loop
Код: Выделить всё
$subfolderName = "UC_" . $customer->numero_uc;
Код: Выделить всё
$folder = $this->createIntoDirectory($this->directory_id[0], $this->graph, $subfolderName);
Код: Выделить всё
public function createIntoDirectory(string $folderId, Graph $graph, string $ucNumber): string|bool
{
try {
$response = $graph->createRequest('POST', "/me/drives/" . $this->drive_id . "/items/$folderId/children")
->attachBody(json_encode([
"name" => $ucNumber,
"folder" => new stdClass()
], JSON_THROW_ON_ERROR))
->setReturnType(DriveItem::class)
->execute();
return $response->getId();
} catch (GuzzleException|GraphException) {
return $this->fetchExistenteDirectory($folderId, $graph, $ucNumber);
}
}
Here the function:
Код: Выделить всё
public function fetchExistenteDirectory(string $folderId, Graph $graph, string $ucNumber): string|bool
{
try {
$folder = $graph->createRequest('GET', "/me/drives/" . $this->drive_id . "/items/$folderId/children")
->setReturnType(DriveItem::class)
->execute();
foreach ($folder as $item) {
if ($item->getName() === $ucNumber) {
return $item->getId();
}
}
return false;
} catch (GuzzleException|GraphException) {
return false;
}
}
Questions:
Where is the PDF? The PDF are converted images from URLs that I fetch from my database.
What is a UC?: is like users, it come from Portuguese word "unidade consumidora" or "consumer unit", each of then come from an array that I fetch from my database.
If you have any questions about the code or the process just ask.
(English isn't my mother tongue, so sorry for any grammatical error).
I tried to create a loop using sleep or increasing time of execution on my PHP but still nothing.
Источник: https://stackoverflow.com/questions/781 ... ng-folders
Мобильная версия