Accessing Gemini API via PHP
I am new to the Gemini API and I have been looking through some of the Java examples and trying to get them working in PHP.
Each time I try running my PHP script I get an error back from Gemini and as I am not the administrator of Gemini system I cannot see the error logs.
Here's what I have come up with in PHP (uses the ZendHttpClient) for adding a comment to an existing issue:
// Preforming a POST request with ZendHttpClient
$client = new ZendHttpClient();
$client->setUri($geminiUrl.'/api/issues.ashx/issues/'.$issueId.'/comments');
$client->setConfig(array(
'maxredirects' => 0,
'timeout' => 30));
$client->setMethod(ZendHttpClient::POST);
// Set headers
$client->setHeaders('Content-type', 'text/xml');
$client->setHeaders('Accept', 'application/json');
$client->setHeaders('gemini-username-token', $geminiUsername);
$client->setHeaders('gemini-password-token', md5($geminiPassword));
// Set XML and POST
$xml = '<?xml version="1.0" encoding="utf-8"?>
<IssueCommentEN>
<VisibilityMemberType>2</VisibilityMemberType>
<CommentId>0</CommentId>
<IssueId>'.$issueId.'</IssueId>
<ProjectId>1</ProjectId>
<Comment>Test comment from PHP to Gemini API</Comment>
<UserName>'.$geminiUsername.'</UserName>
<IsClosing>false</IsClosing>
<Visibility>1</Visibility>
<HasRestrictedVisibility>false</HasRestrictedVisibility>
</IssueCommentEN>';
$client->setParameterPost($xml);
$response = $client->request();
Here's the vardump() from $client and $response:
object(ZendHttpClient)[2]
protected 'config' =>
array
'maxredirects' => int 0
'strictredirects' => boolean false
'useragent' => string 'ZendHttpClient' (length=16)
'timeout' => int 30
'adapter' => string 'ZendHttpClientAdapterSocket' (length=31)
'httpversion' => string '1.1' (length=3)
'keepalive' => boolean false
'storeresponse' => boolean true
'strict' => boolean true
protected 'adapter' =>
object(ZendHttpClientAdapterSocket)[4]
protected 'socket' => null
protected 'connectedto' =>
array
0 => null
1 => null
protected 'config' =>
array
'persistent' => boolean false
'ssltransport' => string 'ssl' (length=3)
'sslcert' => null
'sslpassphrase' => null
'maxredirects' => int 0
'strictredirects' => boolean false
'useragent' => string 'ZendHttpClient' (length=16)
'timeout' => int 30
'httpversion' => string '1.1' (length=3)
'keepalive' => boolean false
'storeresponse' => boolean true
'strict' => boolean true
protected 'method' => string 'POST' (length=4)
protected 'context' => resource(20, stream-context)
protected 'uri' =>
object(ZendUriHttp)[3]
protected 'username' => string '' (length=0)
protected 'password' => string '' (length=0)
protected 'host' => string 'urlremoved.com' (length=16)
protected 'port' => int 80
protected 'path' => string '/gemini/Error.aspx' (length=18)
protected 'query' => string 'aspxerrorpath=/gemini/api/issues.ashx/issues/13586/comments' (length=59)
protected 'fragment' => string '' (length=0)
protected 'regex' =>
array
'escaped' => string '%[[:xdigit:]]{2}' (length=16)
'unreserved' => string '[A-Za-z0-9-.!~'()[]]' (length=24)
'segment' => string '(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~'()[]:@&=+$,;])' (length=54)
'path' => string '(?:\/(?:(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~'()[]:@&=+$,;]))?)+' (length=66)
'uric' => string '(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~'()[];\/?:@&=+$,])' (length=56)
protected 'scheme' => string 'http' (length=4)
protected 'headers' =>
array
'accept' =>
array
0 => string 'Accept' (length=6)
1 => string 'application/json' (length=16)
'gemini-username-token' =>
array
0 => string 'gemini-username-token' (length=21)
1 => string 'myusername' (length=19)
'gemini-password-token' =>
array
0 => string 'gemini-password-token' (length=21)
1 => string 'mypasswordinmd5format' (length=32)
protected 'method' => string 'GET' (length=3)
protected 'paramsGet' =>
array
empty
protected 'paramsPost' =>
array
empty
protected 'enctype' => string 'application/x-www-form-urlencoded' (length=33)
protected 'rawpostdata' => null
protected 'auth' => null
protected 'files' =>
array
empty
protected 'cookiejar' => null
protected 'lastrequest' => string 'POST /gemini/api/issues.ashx/issues/13586/comments HTTP/1.1
Host: urlremoved.com
Connection: close
Accept-encoding: gzip, deflate
User-Agent: ZendHttpClient
Content-type: text/xml
Accept: application/json
gemini-username-token: myusername
gemini-password-token: mypasswordinmd5format
Content-Length: 0
' (length=338)
protected 'lastresponse' =>
object(ZendHttpResponse)[6]
protected 'version' => string '1.1' (length=3)
protected 'code' => int 302
protected 'message' => string 'Found' (length=5)
protected 'headers' =>
array
'Connection' => string 'close' (length=5)
'Date' => string 'Sat, 28 Nov 2009 13:32:57 GMT' (length=29)
'Server' => string 'Microsoft-IIS/6.0' (length=17)
'Microsoftofficewebserver' => string '5.0Pub' (length=7)
'X-powered-by' => string 'ASP.NET' (length=7)
'X-aspnet-version' => string '2.0.50727' (length=9)
'Location' => string '/gemini/Error.aspx?aspxerrorpath=/gemini/api/issues.ashx/issues/13586/comments' (length=78)
'Cache-control' => string 'private' (length=7)
'Content-type' => string 'text/html; charset=utf-8' (length=24)
'Content-length' => string '215' (length=3)
protected 'body' => string '<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="%2fgemini%2fError.aspx%3faspxerrorpath%3d%2fgemini%2fapi%2fissues.ashx%2fissues%2f13586%2fcomments">here</a>.</h2>
</body></html>
' (length=215)
protected 'redirectCounter' => int 1
object(ZendHttpResponse)[6]
protected 'version' => string '1.1' (length=3)
protected 'code' => int 302
protected 'message' => string 'Found' (length=5)
protected 'headers' =>
array
'Connection' => string 'close' (length=5)
'Date' => string 'Sat, 28 Nov 2009 13:32:57 GMT' (length=29)
'Server' => string 'Microsoft-IIS/6.0' (length=17)
'Microsoftofficewebserver' => string '5.0_Pub' (length=7)
'X-powered-by' => string 'ASP.NET' (length=7)
'X-aspnet-version' => string '2.0.50727' (length=9)
'Location' => string '/gemini/Error.aspx?aspxerrorpath=/gemini/api/issues.ashx/issues/13586/comments' (length=78)
'Cache-control' => string 'private' (length=7)
'Content-type' => string 'text/html; charset=utf-8' (length=24)
'Content-length' => string '215' (length=3)
protected 'body' => string '<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="%2fgemini%2fError.aspx%3faspxerrorpath%3d%2fgemini%2fapi%2fissues.ashx%2fissues%2f13586%2fcomments">here</a>.</h2>
</body></html>
' (length=215)
Any ideas where I am going wrong?
Thanks for any help!
sebf
· 1 |
|
Saturday, November 28, 2009, 1:41:04 PM |