Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Retrieving access code server side

  1. #11

    Default

    Now it works much better but still is not quite good. Weird error at the end of successful call.

    Log looks :
    23:03:42.955 [http-apr-8080-exec-6] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Connection request: [route: {s}->https://graph.facebook.com][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 100]
    23:03:43.037 [http-apr-8080-exec-6] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Connection leased: [id: 0][route: {s}->https://graph.facebook.com][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 100]
    23:03:43.315 [http-apr-8080-exec-6] DEBUG o.a.h.i.c.DefaultClientConnectionOperator - Connecting to graph.facebook.com:443
    23:03:43.958 [http-apr-8080-exec-6] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: best-match
    23:03:44.122 [Finalizer] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Connection manager is shutting down
    23:03:44.124 [Finalizer] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Connection manager shut down
    23:03:44.162 [http-apr-8080-exec-6] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
    23:03:44.164 [http-apr-8080-exec-6] DEBUG o.a.h.c.p.RequestProxyAuthentication - Proxy auth state: UNCHALLENGED
    23:03:44.167 [http-apr-8080-exec-6] DEBUG o.a.h.impl.client.DefaultHttpClient - Attempt 1 to execute request
    23:03:44.168 [http-apr-8080-exec-6] DEBUG o.a.h.i.conn.DefaultClientConnection - Sending request: POST /oauth/access_token HTTP/1.1
    23:03:44.170 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - >> "POST /oauth/access_token HTTP/1.1[\r][\n]"
    23:03:44.176 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - >> "Accept: application/json, application/*+json[\r][\n]"
    23:03:44.177 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - >> "Content-Type: application/x-www-form-urlencoded[\r][\n]"
    23:03:44.178 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - >> "Authorization: Basic NTEzODgzNDc4NjMzNTkyOjYzYThhOWM2ZWU5MjXXXXXXXXXXXX XXXXhZWJhOWZh[\r][\n]"
    23:03:44.178 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - >> "Content-Length: 102[\r][\n]"
    23:03:44.179 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - >> "Host: graph.facebook.com[\r][\n]"
    23:03:44.179 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - >> "Connection: Keep-Alive[\r][\n]"
    23:03:44.180 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - >> "User-Agent: Apache-HttpClient/4.2.2 (java 1.5)[\r][\n]"
    23:03:44.180 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - >> "[\r][\n]"
    23:03:44.181 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - >> POST /oauth/access_token HTTP/1.1
    23:03:44.181 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - >> Accept: application/json, application/*+json
    23:03:44.181 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - >> Content-Type: application/x-www-form-urlencoded
    23:03:44.182 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - >> Authorization: Basic NTEzODgzNDc4NjMzNTkyOjYzYThhOWM2ZWUXXXXXXXXXXXXXXX XXXXXXhOWZh
    23:03:44.182 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - >> Content-Length: 102
    23:03:44.183 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - >> Host: graph.facebook.com
    23:03:44.183 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - >> Connection: Keep-Alive
    23:03:44.183 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - >> User-Agent: Apache-HttpClient/4.2.2 (java 1.5)
    23:03:44.184 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - >> "client_id=513883478XXXXXX&client_secret=63a8a9cXX XXXXXXXXXXba9fa&grant_type=client_credentials"
    23:03:44.371 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "HTTP/1.1 200 OK[\r][\n]"
    23:03:44.381 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "Access-Control-Allow-Origin: *[\r][\n]"
    23:03:44.382 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "Cache-Control: private, no-cache, no-store, must-revalidate[\r][\n]"
    23:03:44.382 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "Content-Type: text/plain; charset=UTF-8[\r][\n]"
    23:03:44.383 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "Expires: Sat, 01 Jan 2000 00:00:00 GMT[\r][\n]"
    23:03:44.384 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "Pragma: no-cache[\r][\n]"
    23:03:44.384 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "X-FB-Rev: 734528[\r][\n]"
    23:03:44.385 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "X-FB-Debug: OG/tgqsKDXegiszj+PinqR8Xzsmo8P+j1KXEUv/fmFo=[\r][\n]"
    23:03:44.385 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "Date: Tue, 12 Feb 2013 21:03:46 GMT[\r][\n]"
    23:03:44.386 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "Connection: keep-alive[\r][\n]"
    23:03:44.387 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "Content-Length: 56[\r][\n]"
    23:03:44.387 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "[\r][\n]"
    23:03:44.391 [http-apr-8080-exec-6] DEBUG o.a.h.i.conn.DefaultClientConnection - Receiving response: HTTP/1.1 200 OK
    23:03:44.392 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - << HTTP/1.1 200 OK
    23:03:44.392 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - << Access-Control-Allow-Origin: *
    23:03:44.393 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - << Cache-Control: private, no-cache, no-store, must-revalidate
    23:03:44.393 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - << Content-Type: text/plain; charset=UTF-8
    23:03:44.394 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - << Expires: Sat, 01 Jan 2000 00:00:00 GMT
    23:03:44.394 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - << Pragma: no-cache
    23:03:44.395 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - << X-FB-Rev: 734528
    23:03:44.395 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - << X-FB-Debug: OG/tgqsKDXegiszj+PinqR8Xzsmo8P+j1KXEUv/fmFo=
    23:03:44.396 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - << Date: Tue, 12 Feb 2013 21:03:46 GMT
    23:03:44.396 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - << Connection: keep-alive
    23:03:44.396 [http-apr-8080-exec-6] DEBUG org.apache.http.headers - << Content-Length: 56
    23:03:44.428 [http-apr-8080-exec-6] DEBUG o.a.h.impl.client.DefaultHttpClient - Connection can be kept alive indefinitely
    23:03:44.504 [http-apr-8080-exec-6] DEBUG org.apache.http.wire - << "access_token=5138XXXXXXX3592|G9CdXXXXXXXXXXXXkYn8 j70"
    23:03:44.505 [http-apr-8080-exec-6] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Connection [id: 0][route: {s}->https://graph.facebook.com] can be kept alive indefinitely
    23:03:44.506 [http-apr-8080-exec-6] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Connection released: [id: 0][route: {s}->https://graph.facebook.com][total kept alive: 1; route allocated: 1 of 5; total allocated: 1 of 100]
    23:05:04.805 [http-apr-8080-exec-6] ERROR c.i.w.c.e.EventRegisterController - Publishing REST error
    org.springframework.web.client.RestClientException : Could not extract response: no suitable HttpMessageConverter found for response type [interface java.util.Map] and content type [text/plain;charset=UTF-8]

    at org.springframework.web.client.HttpMessageConverte rExtractor.extractData(HttpMessageConverterExtract or.java:107) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
    at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:492) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
    at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:447) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
    at org.springframework.web.client.RestTemplate.postFo rObject(RestTemplate.java:295) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
    at org.springframework.social.oauth2.OAuth2Template.p ostForAccessGrant(OAuth2Template.java:221) ~[spring-social-core-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at org.springframework.social.oauth2.OAuth2Template.a uthenticateClient(OAuth2Template.java:187) ~[spring-social-core-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at org.springframework.social.oauth2.OAuth2Template.a uthenticateClient(OAuth2Template.java:174) ~[spring-social-core-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    .................
    That happens on call:
    accessGrant = oauth.authenticateClient();
    Best regards.

  2. #12

    Default

    I can debug Response from FB in IDE and see it contains some data.
    See attach with screenshot.

    UPDATE:
    Odd screen after upload.
    There is LinkedValuedMap with 3 Map entries: client_id + value, client_secret + value, grant_type = client_credentials.
    I don't know if that important for error description, but I decided to give that info.

    Code for error looks like:
    Code:
    package org.springframework.web.client;
    
    public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
    ...........
    	public T extractData(ClientHttpResponse response) throws IOException {
    .......
    		for (HttpMessageConverter messageConverter : this.messageConverters) {
    .....
    		}
    		throw new RestClientException(
    				"Could not extract response: no suitable HttpMessageConverter found for response type [" +
    						this.responseType + "] and content type [" + contentType + "]");
    	}
    Attached Images Attached Images
    Last edited by blandger; Feb 12th, 2013 at 03:28 PM.
    Best regards.

  3. #13

    Default

    Craig, don't you have any more ideas why it can't find suitable 'HttpMessageConverter messageConverter' for received answer from FB ?
    May I can do deeper debug and see structure/answer/response it can't parse properly?
    Best regards.

  4. #14
    Join Date
    Aug 2004
    Posts
    1,067

    Default

    Sorry about that. I've been struggling to get the 1.1.0.M2 releases out and only occasionally glancing at the forums. I saw your post, but thought it might take longer to resolve than I had time for, so I thought I'd just come back to it eventually.

    In short, Facebook's an odd one and not consistent with other OAuth2 providers. That's why Spring Social Facebook has its own subclass of OAuth2Template specifically for Facebook: FacebookOAuth2Template. You can see the full code for FacebookOAuth2Template at https://github.com/SpringSource/spri...2Template.java.

    You'll see there that a special message converter is set to handle Facebook's non-standard way of returning authorization details. If you're working with Facebook, you're probably better using that implementation directly. But if you want to use OAuth2Template, then you'll need to do something similar to what you see in FacebookOAuth2Template.
    Craig Walls
    Spring Social Project Lead

  5. #15

    Default

    Thanks a lot, I've changed
    OAuth2Template oauth = new OAuth2Template(...)
    to
    OAuth2Template oauth = new FacebookOAuth2Template(...)

    now it works as expected and publishes app request to FB user's profile.
    Best regards.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •