phpgoogle-apigoogle-plusgoogle-api-php-clientgoogle-plus-domains

Google + Domain API returns forbidden even on paid account


I have been trying to find the reason for this issue since a long time with no luck:

It was working fine on my paid gmail account @mydomain.com, until last week, when it stopped working without any changes in code files.

And now it has been displaying the following error:

[error] => stdClass Object
    (
        [errors] => Array
            (
                [0] => stdClass Object
                    (
                        [domain] => global
                        [reason] => forbidden
                        [message] => Forbidden
                    )

            )

        [code] => 403
        [message] => Forbidden
    )

Any reason for this?

How to resolve this issue?

Following is my current code:

$url = 'https://www.googleapis.com/plusDomains/v1/people/' . $resultUserData['google_id'] . '/activities';
            $headers = array(
                'Authorization : Bearer ' . $resultUserData['google_access_token'],
                'Content-Type : application/json',                  
            );
            $message = Mage::getStoreConfig('tab1/general/module_choose_upload_1');
            $postImage = SITE_URL.'/media/system/'.Mage::getStoreConfig('tab1/general/upload_1');

            $body = array(
                "object" => array(
                    "originalContent" => $message.$productUrl,
                    "attachments"=> array(
                        array(
                            "url"=>$postImage,
                        )
                    ),
                ),
                "access" => array(
                    "items" => array(
                        array("type" => "domain")
                    ),
                    "domainRestricted" => true
                )
            );

            $data_string = json_encode($body);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_URL, $url);
            $file_result = curl_exec($ch);
            curl_close($ch);
            $file_result = json_decode($file_result);

Please Help!


Solution

  • This is now fixed. The issue was that the email ids that I was using were not having their Google plus profile.

    Just created a Google plus profile and then tried the above code and it worked as expected.