2016-10-31 4 views
1

Google 드라이브에서 파일이 변경되면 구독 신청을하려고합니다. Oauth2 절차를 성공적으로 구현했으며 액세스 토큰을 받았습니다.Google 드라이브 API 푸시 알림 구독 400 "구문 분석 오류"

시청 채널을 구독하려고하면 요청한 내용에 실수가 있음을 의미하는 것으로 가정하는 구문 분석 오류가 발생하지만 이해할 수 없습니다.

가 여기에 내가에서 일하고 있어요 구글에서 자원의 부부에 대한 링크입니다 :

//subscribe to new watch channel 
    $ch = curl_init("https://www.googleapis.com/drive/v3/files/1fEDEciN1h_7MZJmNxmgUF-xxxxxxxxx/watch"); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Authorization: Bearer '. $token["access_token"], 
        'Content-Type: application/json' 
       )); 
    $body_array = array(
        "kind: api#channel", 
        "id: ".generate_uuid(), // Your channel ID. 
        "resourceId: 1fEDEciN1h_7MZJmNxmgUF-xxxxxxxxx", 
        "resourceUri: https://docs.google.com/spreadsheets/d/1fEDEciN1h_7MZJmNxmgUF-xxxxxxxxx/", 
        "type: web_hook", 
        "address: http://exampmle.com/test/drivenotifications/receiver/index.php" // Your receiving URL. 
       ); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $body_array); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $result = curl_exec($ch); 
:

https://developers.google.com/drive/v3/web/push

https://developers.google.com/drive/v3/reference/changes/watch

것은 여기에 푸시 알림을 요청하려면 코드 (PHP)입니다

다음은 오류 응답입니다.

"error": { "errors": [ { "domain": "global", "reason": "parseError", "message": "Parse Error" } ], "code": 400, "message": "Parse Error"}} 

도움/제안 사항을 보내 주시면 감사하겠습니다.

편집

나는 또한 코멘트를 연관 배열 시도 :

$body_array = array(
        "kind"=>"api#channel", 
        "id"=>generate_uuid(), // Your channel ID. 
        "resourceId"=>"1fEDEciN1h_7MZJmNxmgUF-xxxxxxxxx", 
        "resourceUri"=>"https://docs.google.com/spreadsheets/d/1fEDEciN1h_7MZJmNxmgUF-xxxxxxxxx/", 
        "type"=>"web_hook", 
        "address"=>"http://example.com/test/drivenotifications/receiver/index.php" // Your receiving URL. 
       ); 

을하지만 같은 오류가 발생했습니다.

+0

$ body_array에서 숫자 키 배열 –

+0

대신 연관 배열을 사용할 수 있습니까? 좋습니다! @JayRajput! 나는 그것을 할 수도 있다고 생각 ...하지만 연관 배열을 시도하고 여전히 구문 오류가있어. (위 편집 참조) 다른 아이디어? – Richard

+0

[Google 드라이브 푸시 알림 놀이터] (https://pushnotificationsplayground.appspot.com/all)를 확인하여 코드 구현이 올바른지 확인하십시오 (샘플 [https://github.com/googledrive/]). pushnotifications-playground)는 파이썬 기본 코드입니다. 또한 도메인 등록 등의 [푸시 알림] (https://developers.google.com/drive/v3/web/push)을 사용하기 전에 필요한 작업을 완료했는지 확인할 수 있습니다. 희망이 도움이됩니다. –

답변

1

게시물 데이터는 json_encode이어야합니다. CURLOPT_POSTFIELDScurl_setopt을 부르기 전에 $body _array에서 json_encode을 실행하십시오. $body_array이 실행 전에 연관 배열인지 확인하십시오. json_encode

+0

바로 제이입니다! 나는 똑같은 결론에 도달했고 대답을 게시하기 위해 돌아왔다. 그것은 항상 당신이 찾는 3 일을 보내는 간단한 것들이다! ;) 도와 줘서 고마워! – Richard