Мне нужно интегрировать Canva API с моим приложением, поэтому я пишу: [code]public function canva() { $client_id = 'asdasdasd'; // Replace with your Canva client ID $redirect_uri = 'https://example.com/redirect-canva'; // Your callback URI $scope = 'asset:write'; // Adjust scopes as necessary
// Store the code_verifier in session session(['code_verifier' => $code_verifier]); $state = bin2hex(random_bytes(16)); // Generate a random state session(['oauth_state' => $state]);
public function redirect_canva(Request $request) { // Retrieve the authorization code and state from the request $code = $request->input('code'); $state = $request->input('state');
// Retrieve the stored code_verifier and state from the session $stored_state = session('oauth_state'); $code_verifier = session('code_verifier'); // Retrieve the same code_verifier
// Ensure the state matches to prevent CSRF attacks if ($state !== $stored_state) { return response('Invalid state parameter', 400); }
// Ensure the authorization code is present if (!$code) { return response('No authorization code found', 400); }
// Canva API OAuth Token endpoint $token_url = "https://api.canva.com/rest/v1/oauth/token";
// Base64-encode client_id:client_secret $client_id = 'asdasd'; // Replace with your actual Canva client ID $client_secret = 'asdasdasdasdasdasd'; // Replace with your actual Canva client secret $credentials = base64_encode("$client_id:$client_secret");
// Construct the POST fields exactly like in the cURL command you provided $post_fields = "grant_type=authorization_code" . "&code_verifier=" . urlencode($code_verifier) // Properly URL encode the code_verifier . "&code=" . urlencode($code) // Properly URL encode the authorization code . "&redirect_uri=" . urlencode('https://example.com/redirect-canva'); // Properly URL encode the redirect_uri
// Check for cURL errors if ($err) { return response('cURL Error: ' . htmlspecialchars($err), 500); }
// Parse the response $response_data = json_decode($response, true);
if (isset($response_data['access_token'])) { // Store the access token in the session or database session(['canva_access_token' => $response_data['access_token']]);
// Redirect to a success page return redirect('/some-success-page'); // Replace with your desired redirection } else { // Output the full response for debugging return response('Error obtaining access token: ' . json_encode($response_data), 400); } } [/code] Итак, я реализовал все, как здесь: https://www.canva.dev/docs/connect/api-reference/authentication/generate-access-token/, и получил ошибку:< /p>
Мне нужно интегрировать Canva API с моим приложением, поэтому я пишу:
public function canva()
{
$client_id = 'asdasdasd'; // Replace with your Canva client ID
$redirect_uri = ' // Your callback URI
$scope = 'asset:write'; // Adjust scopes as...
Мне нужно интегрировать Canva API с моим приложением, поэтому я пишу:
public function canva()
{
$client_id = 'asdasdasd'; // Replace with your Canva client ID
$redirect_uri = ' // Your callback URI
$scope = 'asset:write'; // Adjust scopes as...
Мне нужно интегрировать Canva API с моим приложением, поэтому я пишу:
public function canva()
{
$client_id = 'asdasdasd'; // Replace with your Canva client ID
$redirect_uri = ' // Your callback URI
$scope = 'asset:write'; // Adjust scopes as...
Я работаю над автоматизацией конвейера создания контента для моего монетизированного канала YouTube. Я создаю простые видео с использованием фиксированного шаблона Canva , а видеоконтент обычно основан на текстовом основании и генерируется из таких...
У меня проблемы с интеграцией редактора Canva SDK (Designbutton) в простую HTML -страницу. Я использую Live Server (VS Code) для запуска его локально.
Предварительный просмотр URL в Canva IS http: // localhost: 5500/, который поддерживается в...