2014-09-24 6 views
0

그래서 PHP cURL을 사용하여 Google 검색 어플라이언스 (GSA)로 콘텐츠 피드를 푸시하는 웹 애플리케이션 용 모듈을 개발하려고합니다. 어플라이언스에 대한 데이터를 포트 19900을 통해 POST 정보로 전송합니다. GSA에 피드를 작성하고 제출하는 데 필요한 설명서를 읽었을 때이 내용이 문제없이 작동해야하지만 서버는 다음과 같이 매우 유용합니다.) 모호하고 대부분 쓸모없는 오류 :Google 검색 어플라이언스 (GSA) 제출 PHP cURL - 400 오류로 콘텐츠 피드

  1. That's an error.

Your client has issued a malformed or illegal request. That's all we know.

나는 우리의 자매 사이트에서 악기에게 GSA 도움이 건축가와 함께이 문제를 해결 있었고, 우리는 우리의 문제의 원인을 확인할 수 없었습니다. 우리 IT 부서에 따르면이 통신을 위해 모든 포트가 열렸으며 폐쇄 된 경우 오류 메시지가 표시되지 않으며 보내는 서버의 IP 주소가 '허용됨'으로 표시되는지 확인했습니다. GSA에서 말할 것도없이, 우린 우연히 만난다. 여기

는 XML 피드 전송하는 코드입니다 :

<?php 
$target_url = 'http://gsadomain.com:19900/xmlfeed'; 

$header = array('Content-Type: multipart/form-data'); 

$fields = array(
    'feedtype'=>'incremental', 
    'datasource'=>'datasourcename', 
    'data'=>'@'.realpath('gsa_feed.xml') 
); 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_USERPWD, "gsaadmin:gsaadminpassword"); 
curl_setopt($ch, CURLOPT_HTTPHEADER,$header); 
curl_setopt($ch, CURLOPT_TIMEOUT,120); 
curl_setopt($ch, CURLOPT_URL,$target_url); 
curl_setopt($ch, CURLOPT_POST,1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); 

$return = curl_exec($ch); 

if (curl_errno($ch)) { 
    $msg = curl_error($ch); 
} 

curl_close ($ch); 

echo $return; 
?> 

을 그리고 여기에 우리가 제출하려는 XML이다 : 우리가보고있는 모든 것을 바탕으로

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE gsafeed PUBLIC "-//Google//DTD GSA Feeds//EN" "http://this.is.the.ip/gsafeed.dtd"> 
<gsafeed> 
    <header> 
     <datasource>datasource</datasource> 
     <feedtype>incremental</feedtype> 
    </header> 
    <group> 
     <record url="http://website.com/mod/view.php?id=15903" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT"> 
      <acl inheritance-type="and-both-permit"> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">customers</principal> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal> 
      </acl> 
      <metadata> 
       <meta name="type" content="module" /> 
       <meta name="id" content="1" /> 
       <meta name="name" content="Module for Everyone" /> 
       <meta name="course_id" content="655" /> 
      </metadata> 
      <content> 
       This is the description of the Module for Everyone. 
     </content> 
     </record> 
     <record url="http://website.com/mod/view.php?id=15904" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT"> 
      <acl inheritance-type="and-both-permit"> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal> 
      </acl> 
      <metadata> 
       <meta name="type" content="module" /> 
       <meta name="id" content="2" /> 
       <meta name="name" content="Module for Partners" /> 
       <meta name="course_id" content="655" /> 
      </metadata> 
      <content> 
       This is the description of the Module for Partners. 
     </content> 
     </record> 
     <record url="http://website.com/mod/view.php?id=15905" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT"> 
      <acl inheritance-type="and-both-permit"> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal> 
      </acl> 
      <metadata> 
       <meta name="type" content="module" /> 
       <meta name="id" content="3" /> 
       <meta name="name" content="Module for Employees" /> 
       <meta name="course_id" content="655" /> 
      </metadata> 
      <content> 
       This is the description of the Module for Employees. 
     </content> 
     </record> 
     <record url="http://website.com/course/view.php?id=655#section-1" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT"> 
      <acl inheritance-type="and-both-permit"> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">customers</principal> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal> 
      </acl> 
      <metadata> 
       <meta name="type" content="topic" /> 
       <meta name="id" content="1" /> 
       <meta name="name" content="Course Topic for Everyone" /> 
       <meta name="course_id" content="655" /> 
      </metadata> 
      <content> 
       This is the description of the Course Topic for All Audiences. 
     </content> 
     </record> 
     <record url="http://website.com/course/view.php?id=655#section-2" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT"> 
      <acl inheritance-type="and-both-permit"> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal> 
      </acl> 
      <metadata> 
       <meta name="type" content="topic" /> 
       <meta name="id" content="2" /> 
       <meta name="name" content="Course Topic for Partners" /> 
       <meta name="course_id" content="655" /> 
      </metadata> 
      <content> 
       This is the description of the Course Topic for Partners. 
     </content> 
     </record> 
     <record url="http://website.com/course/view.php?id=655#section-3" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT"> 
      <acl inheritance-type="and-both-permit"> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal> 
      </acl> 
      <metadata> 
       <meta name="type" content="topic" /> 
       <meta name="id" content="3" /> 
       <meta name="name" content="Course Topic for Employees" /> 
       <meta name="course_id" content="655" /> 
      </metadata> 
      <content> 
       This is the description of the Course Topic for Employees. 
     </content> 
     </record> 
     <record url="http://website.com/course/view.php?id=655" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT"> 
      <acl inheritance-type="and-both-permit"> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">customers</principal> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal> 
      </acl> 
      <metadata> 
       <meta name="type" content="course" /> 
       <meta name="id" content="655" /> 
       <meta name="name" content="Course for Everyone" /> 
       <meta name="course_id" content="655" /> 
      </metadata> 
      <content> 
       This is the description of the Course for Everyone. 
     </content> 
     </record> 
     <record url="http://website.com/course/view.php?id=656" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT"> 
      <acl inheritance-type="and-both-permit"> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal> 
      </acl> 
      <metadata> 
       <meta name="type" content="course" /> 
       <meta name="id" content="656" /> 
       <meta name="name" content="Course for Partners" /> 
       <meta name="course_id" content="656" /> 
      </metadata> 
      <content> 
       This is the description of the Course for Partners. 
     </content> 
     </record> 
     <record url="http://website.com/course/view.php?id=657" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT"> 
      <acl inheritance-type="and-both-permit"> 
       <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal> 
      </acl> 
      <metadata> 
       <meta name="type" content="course" /> 
       <meta name="id" content="657" /> 
       <meta name="name" content="Course for Employees" /> 
       <meta name="course_id" content="657" /> 
      </metadata> 
      <content> 
       This is the description of the Course for Employees. 
     </content> 
     </record> 
    </group> 
</gsafeed> 

,이해야 우리는 아직 벽돌 벽에 뛰어 들고 있습니다. 누구든지 아이디어가 있습니까?

색인을 추가하려는 페이지의 설정 방법으로 인해 어플라이언스가 페이지를 크롤링하면 작동하지 않습니다 (대화식 요소가 너무 많아서 읽은 모든 내용은 GSA는 이들을 적절히 색인 할 수 없습니다).

편집 1 : http://www.google.com/support/enterprise/static/gsa/docs/admin/72/gsa_doc_set/feedsguide/feedsguide.html

편집 2 : 성공 마크는 답변에서 제안한 것처럼, 여기에 GSA 피드 개발자 가이드에 대한 링크입니다! 아래 내 대답을 참조하십시오. 핵심은 cURL이 $ fields 배열의 인코딩을 처리하고 파일 경로가 아닌 파일 내용을 전달하도록하는 것입니다.

답변

1

같은 더

아마도 뭔가 그래서 긴 짧은 이야기, 나는 제대로 제출 피드를 얻을 수 있었고, 그것은 모두 컬 데이터를 처리 상황을해야했다. 나 또는 내가 피드를 제출하려고 노력하고있는 엔지니어도 PHP 용 cURL 플러그인에 대한 많은 경험이 없었으며 입력 필드를 받아들이도록 GSA를 얻는 방법도 없었습니다. this question by Ken에 부분적으로 감사의 answer by ThiefMasternext answer from Czechnology, 위 마이크의 도움으로, 다음 코드를 내놓았다 : 어려움에 대한 컬의 일을하려고 한 http_build_query() 메소드에

<?php 
$target_url = 'http://gsadomain.com:19900/xmlfeed'; 

$header = array('Content-Type: multipart/form-data'); 

$fields = array(
    'feedtype'=>'incremental', 
    'datasource'=>'datasourcename', 
    'data'=>file_get_contents(realpath('gsa_feed.xml')) 
); 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_USERPWD, "gsaadmin:gsaadminpassword"); 
curl_setopt($ch, CURLOPT_HTTPHEADER,$header); 
curl_setopt($ch, CURLOPT_TIMEOUT,120); 
curl_setopt($ch, CURLOPT_URL,$target_url); 
curl_setopt($ch, CURLOPT_POST,1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); 

$return = curl_exec($ch); 

if (curl_errno($ch)) { 
    $msg = curl_error($ch); 
} 

curl_close ($ch); 

echo $return; 
?> 

했다 POST 데이터의 경계를 올바르게 설정하지 못했습니다.

나중에 XML의 일부 필드에서 약간의 어려움을 겪었지만 대부분은 앰퍼샌드, 작은 따옴표 및 큰 따옴표를 str_replace하는 것을 잊었 기 때문입니다. 일단 XML을 처리하면 XML이 제대로 분석되고 모든 것이 실행됩니다.

0

저는 GSA API에 익숙하지 않지만 XML 데이터를 실제로 보내지는 않습니다. data 매개 변수로 보낼 문자열 값은 @/path/to/gsa_feed.xml과 같을 것입니다. 실제로 XML을 POST해야한다고 생각하겠습니까?

$fields = array(
    'feedtype'=>'incremental', 
    'datasource'=>'datasourcename', 
    'data'=> file_get_contents(realpath('gsa_feed.xml')) 
); 
+0

방금이 장면을 포기하고 행운이 없었습니다. 문제의 PHP 스크립트는 xml 파일을 작성하기 때문에 처음에는 '$ fields = array ('fieldtype '=>'incremental ','datasource '=>'datasourcename ',' data '=> $ string);' 그게 작동하지 않으면, 나는 @ path/to/gsa_feed.xml 메쏘드로 전환했다. (설명서에서 볼 수 있듯이, 내가 원했던 것일 수도있다.) –

+0

@JoshC 귀하의 질문에 API 설명서. 당신이 보여 주신 PHP에서, 거기에 어디 XML 파일을 만들 것입니다. 당신이 보여주는 무엇을 몇 가지 데이터 필드 중 하나는 문제 의이 문자열입니다 간단한 cURL POST입니다. –

+0

@ 마크 브랜트 (Mark Brant) 방금 Google에서 개발자 가이드에 대한 링크를 포함하도록 원래 게시물을 편집했습니다. 불행히도 자신 만의 설정 방법에 대해 너무 많은 지침을 제공하지는 않습니다. 피드 스크립트입니다. http://www.google.com/support/enterprise/static/gsa/docs/admin/72/gsa_doc_set/feedsguide/feedsguide.html 링크가 다시 나타납니다. –