Hi.
I am trying to post comment on an Object (that is, a post, checkin,
photopost etc)
The problem is that a Post call with out a parameter works (this too
faces trouble at times), but the calls with Parameters don't work and
i get 417 Http Status or at times 500.
for example, here is what i am doing for testing purposes
int status=response.getStatusLine().getStatusCode();
System.out.println("Returned status -> "+status);
InputStream is2= response.getEntity().getContent();
for (int i = is2.read(); i > -1; i = is2.read()) {
System.out.write(i);
}
--------------------------------------------------------------------------- ---------------------------------------------------------------------
What am i doing wrong? I have tried many things but the most
appropriate to me is what i have shared here. Any help would be great.
I have developed a Java wrapper for Brightkite Api, however, this is
the only thing missing (i.e posting comments and creating objects). By
the way Likes call doesn't work too, I get a success response but
Likes don't appear !
Signing the OAuth call means you're ensuring that after it's been
signed, the call does not change (that's the security OAuth provides -
preventing tampering with authenticated calls). Thus, you have to add
your parameters BEFORE you sign the OAuth call - adding a parameter
afterwards is tantamount to tampering with the call.
Let me know if this helps.
- Jordan
On Oct 11, 11:27 pm, Codomaniac <mauze_muaw...@hotmail.com> wrote:
> Hi.
> I am trying to post comment on an Object (that is, a post, checkin,
> photopost etc)
> The problem is that a Post call with out a parameter works (this too
> faces trouble at times), but the calls with Parameters don't work and
> i get 417 Http Status or at times 500.
> for example, here is what i am doing for testing purposes
> int status=response.getStatusLine().getStatusCode();
> System.out.println("Returned status -> "+status);
> InputStream is2= response.getEntity().getContent();
> for (int i = is2.read(); i > -1; i = is2.read()) {
> System.out.write(i);
> }
> --------------------------------------------------------------------------- ---------------------------------------------------------------------
> What am i doing wrong? I have tried many things but the most
> appropriate to me is what i have shared here. Any help would be great.
> I have developed a Java wrapper for Brightkite Api, however, this is
> the only thing missing (i.e posting comments and creating objects). By
> the way Likes call doesn't work too, I get a success response but
> Likes don't appear !
Indeed you are right, i must have forgotten to post the correct code.
However, doing what you told me to , I get following response ...
Returned status -> 417
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=iso-8859-1">
<TITLE>ERROR: The requested URL could not be retrieved</TITLE>
<STYLE type="text/css"><!--BODY{background-color:#ffffff;font-
family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The requested URL could not be retrieved</H2>
<HR noshade size="1px">
<P>
While trying to process the request:
<PRE>
POST /places/4d65bf3e648846b767bc58e6fc5cee12/checkins.xml HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: OAuth
oauth_token="NTQ5ZWEzYWQ1NmVmNDM5ZjczNzJkMGEx",
oauth_consumer_key="M2Y1ODYxYjI1ZDkzMmY0OGI0OGY0ZTU4",
oauth_version="1.0", oauth_signature_method="HMAC-
SHA1", oauth_timestamp="1286886342",
oauth_nonce="-1429113925153201057",
oauth_signature="MjotZ5KUecMoiQrP5cq3uRwQ8Kk%3D"
Content-Length: 34
Host: brightkite.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.0-beta1 (java 1.4)
Expect: 100-Continue
</PRE>
<P>
The following error was encountered:
<UL>
<LI>
<STRONG>
Invalid Request
</STRONG>
</UL>
<P>
Some aspect of the HTTP Request is invalid. Possible problems:
<UL>
<LI>Missing or unknown request method
<LI>Missing URL
<LI>Missing HTTP Identifier (HTTP/1.0)
<LI>Request is too large
<LI>Content-Length missing for POST or PUT requests
<LI>Illegal character in hostname; underscores are not allowed
</UL>
<P>Your cache administrator is <A HREF="mailto:root">root</A>.
<BR clear="all">
<HR noshade size="1px">
<ADDRESS>
Generated Tue, 12 Oct 2010 12:24:59 GMT by gateway.csquareonline.local
(squid/2.7.STABLE6)
</ADDRESS>
</BODY></HTML>
> Indeed you are right, i must have forgotten to post the correct code.
> However, doing what you told me to , I get following response ...
> Returned status -> 417
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
> <HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html;
> charset=iso-8859-1">
> <TITLE>ERROR: The requested URL could not be retrieved</TITLE>
> <STYLE type="text/css"><!--BODY{background-color:#ffffff;font-
> family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
> </HEAD><BODY>
> <H1>ERROR</H1>
> <H2>The requested URL could not be retrieved</H2>
> <HR noshade size="1px">
> <P>
> While trying to process the request:
> <PRE>
> POST /places/4d65bf3e648846b767bc58e6fc5cee12/checkins.xml HTTP/1.1
> Content-Type: application/x-www-form-urlencoded
> Authorization: OAuth
> oauth_token="NTQ5ZWEzYWQ1NmVmNDM5ZjczNzJkMGEx",
> oauth_consumer_key="M2Y1ODYxYjI1ZDkzMmY0OGI0OGY0ZTU4",
> oauth_version="1.0", oauth_signature_method="HMAC-
> SHA1", oauth_timestamp="1286886342",
> oauth_nonce="-1429113925153201057",
> oauth_signature="MjotZ5KUecMoiQrP5cq3uRwQ8Kk%3D"
> Content-Length: 34
> Host: brightkite.com
> Connection: Keep-Alive
> User-Agent: Apache-HttpClient/4.0-beta1 (java 1.4)
> Expect: 100-Continue
> </PRE>
> <P>
> The following error was encountered:
> <UL>
> <LI>
> <STRONG>
> Invalid Request
> </STRONG>
> </UL>
> <P>
> Some aspect of the HTTP Request is invalid. Possible problems:
> <UL>
> <LI>Missing or unknown request method
> <LI>Missing URL
> <LI>Missing HTTP Identifier (HTTP/1.0)
> <LI>Request is too large
> <LI>Content-Length missing for POST or PUT requests
> <LI>Illegal character in hostname; underscores are not allowed
> </UL>
> <P>Your cache administrator is <A HREF="mailto:root">root</A>.
int status=response.getStatusLine().getStatusCode();
System.out.println("Returned status -> "+status);
InputStream is2= response.getEntity().getContent();
for (int i = is2.read(); i > -1; i = is2.read()) {
System.out.write(i);
}
--------------------------------------------------------------------------- --------------------------------------------------------------------------- --------------------------------------------------------------------------- ----------------------------
I get the same error....
Returned status -> 417
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=iso-8859-1">
<TITLE>ERROR: The requested URL could not be retrieved</TITLE>
<STYLE type="text/css"><!--BODY{background-color:#ffffff;font-
family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The requested URL could not be retrieved</H2>
<HR noshade size="1px">
<P>
While trying to process the request:
<PRE>
POST /objects/aa6f52d903ec8407417238a609314a2b/comments.xml HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: OAuth
oauth_token="MGNjMTFhMzFiMTExY2JjNGMzM2VmZDVh",
oauth_consumer_key="M2Y1ODYxYjI1ZDkzMmY0OGI0OGY0ZTU4",
oauth_version="1.0", oauth_signature_method="HMAC-
SHA1", oauth_timestamp="1286945372", oauth_nonce="
7549350979876047373",
oauth_signature="egZq3RGEYiCpU3ZqSBgeaGRzX%2F4%3D"
Content-Length: 34
Host: brightkite.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.0-beta1 (java 1.4)
Expect: 100-Continue
</PRE>
<P>
The following error was encountered:
<UL>
<LI>
<STRONG>
Invalid Request
</STRONG>
</UL>
<P>
Some aspect of the HTTP Request is invalid. Possible problems:
<UL>
<LI>Missing or unknown request method
<LI>Missing URL
<LI>Missing HTTP Identifier (HTTP/1.0)
<LI>Request is too large
<LI>Content-Length missing for POST or PUT requests
<LI>Illegal character in hostname; underscores are not allowed
</UL>
<P>Your cache administrator is <A HREF="mailto:root">root</A>.
<BR clear="all">
<HR noshade size="1px">
<ADDRESS>
Generated Wed, 13 Oct 2010 04:48:45 GMT by gateway.csquareonline.local
(squid/2.7.STABLE6)
</ADDRESS>
</BODY></HTML>
I can attest that the OAuth processes are working, and that the API is
working - if you wish to verify for testing purposes, try just
explicitly authenticating (meaning, don't use OAuth, just include
`username` and `password` parameters.
If that call works, then the problem is in your OAuth library and
implementation. It looks like you're using http://code.google.com/p/oauth-signpost/ - I notice the example code differs from your example:
// create an HTTP request to a protected resource
URL url = new URL("http://api.example.com/protected")
HttpURLConnection request = (HttpURLConnection)
url.openConnection();
// sign the request (consumer is a Signpost
DefaultOAuthConsumer)
consumer.sign(request);
// send the request
request.connect();
Specifically, the example says to use request.connect, while your code
uses httpClient.execute(request). Perhaps this is the issue?
- Jordan
On Oct 12, 9:50 pm, Codomaniac <mauze_muaw...@hotmail.com> wrote:
> That wasn't working, i had checked it too(as i said, i have tried many
> things). In the following piece of code i am trying to comment on a
> checkin
> int status=response.getStatusLine().getStatusCode();
> System.out.println("Returned status -> "+status);
> InputStream is2= response.getEntity().getContent();
> for (int i = is2.read(); i > -1; i = is2.read()) {
> System.out.write(i);
> }
> --------------------------------------------------------------------------- --------------------------------------------------------------------------- --------------------------------------------------------------------------- ----------------------------
> I get the same error....
> Returned status -> 417
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
> <HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html;
> charset=iso-8859-1">
> <TITLE>ERROR: The requested URL could not be retrieved</TITLE>
> <STYLE type="text/css"><!--BODY{background-color:#ffffff;font-
> family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
> </HEAD><BODY>
> <H1>ERROR</H1>
> <H2>The requested URL could not be retrieved</H2>
> <HR noshade size="1px">
> <P>
> While trying to process the request:
> <PRE>
> POST /objects/aa6f52d903ec8407417238a609314a2b/comments.xml HTTP/1.1
> Content-Type: application/x-www-form-urlencoded
> Authorization: OAuth
> oauth_token="MGNjMTFhMzFiMTExY2JjNGMzM2VmZDVh",
> oauth_consumer_key="M2Y1ODYxYjI1ZDkzMmY0OGI0OGY0ZTU4",
> oauth_version="1.0", oauth_signature_method="HMAC-
> SHA1", oauth_timestamp="1286945372", oauth_nonce="
> 7549350979876047373",
> oauth_signature="egZq3RGEYiCpU3ZqSBgeaGRzX%2F4%3D"
> Content-Length: 34
> Host: brightkite.com
> Connection: Keep-Alive
> User-Agent: Apache-HttpClient/4.0-beta1 (java 1.4)
> Expect: 100-Continue
> </PRE>
> <P>
> The following error was encountered:
> <UL>
> <LI>
> <STRONG>
> Invalid Request
> </STRONG>
> </UL>
> <P>
> Some aspect of the HTTP Request is invalid. Possible problems:
> <UL>
> <LI>Missing or unknown request method
> <LI>Missing URL
> <LI>Missing HTTP Identifier (HTTP/1.0)
> <LI>Request is too large
> <LI>Content-Length missing for POST or PUT requests
> <LI>Illegal character in hostname; underscores are not allowed
> </UL>
> <P>Your cache administrator is <A HREF="mailto:root">root</A>.
//Brighkiteproperties is my custom bean and it has the tokens etc
DefaultOAuthConsumer consumer=new
DefaultOAuthConsumer(brightKiteProperties.getConsumerKey(),brightKiteProper ties.getConsumerSecret());
At this point, I think the issues are in your code/library and not
with our API, so this group is no longer the best place to discuss it.
However, I'm still more than welcome to help you work through it -
please email me directly at < jor...@brightkite.com >.
If it turns out there's any issue with the API, or if we come up with
useful information for other API developers, I'll post it here so it
can help others.
- Jordan
On Oct 19, 4:43 am, Codomaniac <mauze_muaw...@hotmail.com> wrote:
It works now, but sadly i used (unwillingly :D) my Username and
password. Now I am trying to do it with OAuth, in the mean time any
help would be nice !
which OAuth do i use for this ? I know two implementations,
CommonsHttpOAuthConsumer and DefaultOAuthConsumer. However, I can't
seem to find any class that signs a POSTMETHOD object ?
Please email me directly at jor...@brightkite.com for further
discussion on this topic. If the API functions, and the problem is in
your implementation - although I will be happy to help you via email -
the Google Group is not an appropriate place for figuring out client-
side implementation issues.
Thanks!
- Jordan
On Oct 25, 6:16 am, Codomaniac <mauze_muaw...@hotmail.com> wrote: