How to enable an app in the Google Chat API relative to a 403 error

I am using/want the Google Chat API to send messages to a specific space. However, when I tried to add the bot to the space, I had this error :

"error": {
    "code": 403,
    "message": "The requested membership is for an app that is disabled by the developer. To add this app to the space, request the developer to enable it.",
    "status": "PERMISSION_DENIED"
  }
}

In order to add the bot to the space, I am using this code, which takes in my space ID and the Access token :

function add_bot_to_space($space_id, $access_token) {
    // Prepare the URL to add a member (bot) to the space
    $url = "https://chat.googleapis.com/v1/{$space_id}/members";

    // Prepare the headers for the API request, including the access token
    $headers = [
        'Authorization: Bearer ' . $access_token,  // Bearer token authorization
        'Content-Type: application/json'  // Set the content type to JSON
    ];

    // Prepare the member data to add (in this case, the bot)
    $data = [
        "member" => [
            "name" => "users/app",  // Correct format for bot users
            "type" => "BOT"
        ]
    ];

    // Send the POST request to the Google Chat API to add the bot
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
}

The problem is what App is disabled means and how can I handle this issue. If you have any ideas, that would be great.

Upvotes: 0

Views: 58

Answers (0)

Related Questions