Why I am getting invalid_request from Graph api when invoked from my app? - facebook

When I make the following request from browser, it works.
https://graph.facebook.com/app?access_token=<a valid token>
However, this same call fails with the following error when done from my code, for the exact same token which worked in the browser.
2 * Client out-bound request
2 > GET https://graph.facebook.com/app?access_token=<the fb token>
2 * Client in-bound response
2 < 400
2 < Content-Type: text/javascript; charset=UTF-8
2 < WWW-Authenticate: OAuth "Facebook Platform" "invalid_request" "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api"
2 < Access-Control-Allow-Origin: *
2 < X-FB-Rev: 1674690
2 < Pragma: no-cache
2 < Cache-Control: no-store
2 < Facebook-API-Version: v1.0
2 < Expires: Sat, 01 Jan 2000 00:00:00 GMT
2 < X-FB-Debug: <some string>
2 < Date: Mon, 06 Apr 2015 13:46:57 GMT
2 < Connection: keep-alive
2 < Content-Length: 183
2 <
{"error":{"message":"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api","type":"GraphMethodException","code":100}}
My client-side code which makes this call is:-
ClientResponse r = httpClient.resource("https://graph.facebook.com/app")
.queryParam("access_token", fbAccessToken).accept(MediaType.APPLICATION_JSON)
.get(ClientResponse.class);
FBAccessTokenResponse res = r.getEntity(FBAccessTokenResponse.class);
return res;
The other interesting fact is that the app code works if the fb token is for me (the app developer) or few FB test users. For other actual users it fails with this error, for my app only.

Related

Microsoft storage emulator missing headers with azure sdk 12.4.0

I'm using Microsoft storage emulator for development and in concrete, the method that gives me an error is the exists(), the error is a null pointer exception.
Looking deeply in the library, I was able to find that it was requesting a couple of headers, then I notice that the endpoint response from azure blob storage is different than from azure storage emulator:
From the emulator:
curl -G http://127.0.0.1:10000/devstoreaccount1/default?restype=container -v -H 'x-ms-version: 2019-07-07'
* Connected to 127.0.0.1 (127.0.0.1) port 10000 (#0)
> GET /devstoreaccount1/default?restype=container HTTP/1.1
> Host: 127.0.0.1:10000
> User-Agent: curl/7.51.0
> Accept: */*
> x-ms-version: 2019-07-07
>
< HTTP/1.1 200 OK
< Transfer-Encoding: chunked
< Last-Modified: Mon, 24 Feb 2020 18:21:08 GMT
< ETag: "0x8D7B95651C1DCC0"
< Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
< x-ms-request-id: 63875efa-4883-45fc-8dee-2481781ae3de
< x-ms-version: 2019-07-07
< x-ms-lease-status: unlocked
< x-ms-lease-state: available
< x-ms-blob-public-access: container
< Date: Mon, 24 Feb 2020 20:28:26 GMT
From storage:
curl -Gv https://account.blob.core.windows.net/default?restype=container -H 'x-ms-version: 2019-07-07'
> GET /roo?restype=container HTTP/1.1
> Host: account.blob.core.windows.net
> User-Agent: curl/7.51.0
> Accept: */*
> x-ms-version: 2019-07-07
>
< HTTP/1.1 200 OK
< Content-Length: 0
< Last-Modified: Mon, 24 Feb 2020 18:57:04 GMT
< ETag: "0x8D7B95B569707A4"
< Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
< x-ms-request-id: 9548781e-a01e-002f-0a51-eb0305000000
< x-ms-version: 2019-07-07
< x-ms-lease-status: unlocked
< x-ms-lease-state: available
< x-ms-has-immutability-policy: false
< x-ms-has-legal-hold: false
< x-ms-blob-public-access: container
< x-ms-default-encryption-scope: $account-encryption-key
< x-ms-deny-encryption-scope-override: false
< Date: Mon, 24 Feb 2020 20:29:01 GMT
<
* Curl_http_done: called premature == 0
* C
As you can see, there are a couple of headers missing in the storage emulator.
Is there a way to get around this ?
how recommended it is to wrap the exists() method on my own just to be able to use the development storage emulator ?
Versions:
StorageEmulator: 5.10
SDK: 12.4.0
Language: Java
Thanks.
Note: I have removed information as tls and ips from the curl responses.
Can you please try to use Azurite instead and start it with the --loose parameter to ignore unsupported headers?
https://github.com/Azure/Azurite/

What could cause a 302 redirect?

I have a wordpress site and I have a blog. When I try to share my blog post on FB http://videoefekt.cz/?p=472 , it shows the thumb of my homepage. I tried to change permalinks to clear, deactivate plugins and chceck .htaccess file, everything looks fine, but the FB sharing debugger shows I have 302 HTTP Redirect to my homepage, can anyone tell me what could cause this problem ?
Simulate the facebook crawler access to your site and it made redirect to home page when using ipv6 address. Possibly you have misconfig when the request is from ipv6 address.
curl -H "User-Agent: facebookexternalhit/1.1" "http://videoefekt.cz/?p=472" -vvvv -6
* About to connect() to videoefekt.cz port 80 (#0)
* Trying 2a02:2b88:1:4::a6...
* Connected to videoefekt.cz (2a02:2b88:1:4::a6) port 80 (#0)
> GET /?p=472 HTTP/1.1
> Host: videoefekt.cz
> Accept: */*
> User-Agent: facebookexternalhit/1.1
>
< HTTP/1.1 302 Found
< Date: Thu, 04 Jan 2018 04:16:32 GMT
< Server: Apache
< Pragma: no-cache
< Expires: Wed, 11 Jan 1984 05:00:00 GMT
< Cache-Control: no-cache, must-revalidate, max-age=0
< Link: <http://videoefekt.cz/wp-json/>; rel="https://api.w.org/"
< Set-Cookie: _icl_current_language=cs; expires=Fri, 05-Jan-2018 04:16:33 GMT; Max-Age=86400; path=/
< Set-Cookie: wfvt_3708104896=5a4daaa1e2090; expires=Thu, 04-Jan-2018 04:46:33 GMT; Max-Age=1800; path=/; HttpOnly
< Set-Cookie: PHPSESSID=8a1a1d9247ac9d9707b616c6c0ad2ccc; path=/
< Upgrade: h2,h2c
< Connection: Upgrade
< Location: http://videoefekt.cz/
< Vary: User-Agent
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
<
* Connection #0 to host videoefekt.cz left intact

Empty response from Bitstamp.net

I am trying to use the private api from Bitstamp to query for my account's balance. I believe I am posting the right data as no error is returned but Bitstamp's answer is always empty
* Trying 107.154.249.133...
* Connected to www.bitstamp.net (107.154.249.133) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection:
ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:#STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* NPN, negotiated HTTP1.1
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: OU=Domain Control Validated; CN=*.bitstamp.net
* start date: Apr 8 14:11:39 2015 GMT
* expire date: Apr 8 15:48:13 2018 GMT
* subjectAltName: www.bitstamp.net matched
* issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.;
OU=http://certs.godaddy.com/repository/; CN=Go Daddy Secure Certificate
Authority - G2
* SSL certificate verify ok.
> POST /api/v2/balance HTTP/1.1
Host: www.bitstamp.net
User-Agent: Bitstamp C++ API Client
Accept: */*
Content-Length: 134
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 134 out of 134 bytes
< HTTP/1.1 301 MOVED PERMANENTLY
< Access-Control-Allow-Headers: x-requested-with, Content-Type, origin, accept, cache-control
< Access-Control-Allow-Methods: POST, GET
< Access-Control-Allow-Origin: *
< Content-Language: en
< Content-Type: text/html; charset=utf-8
< Date: Fri, 08 Sep 2017 17:46:41 GMT
< Location: http://www.bitstamp.net/api/v2/balance/
< Server: Apache
< Strict-Transport-Security: max-age=63072000; includeSubDomains
< Vary: Accept-Language
< X-Frame-Options: SAMEORIGIN
< Content-Length: 0
< Connection: keep-alive
< Set-Cookie: visid_incap_99025=wHhR5uPzT92ReB9XbeNToIHXslkAAAAAQUIPAAAAAAAbNQJEog5ZojcqdOv0dFhd; expires=Sat, 08 Sep 2018 10:32:13 GMT; path=/; Domain=.bitstamp.net
< Set-Cookie: nlbi_99025=VyBXXwUOsQHckThX8F1n9AAAAABOW3tLZ0nUHyp47yinIimv; path=/; Domain=.bitstamp.net
< Set-Cookie: incap_ses_569_99025=04PeXe3KGFAAVw//8n7lB4HXslkAAAAA09BkGnsaiskl2dkFxzhFXQ==; path=/; Domain=.bitstamp.net
< X-Iinfo: 9-15073063-15060114 PNNN RT(1504892800858 31) q(0 0 0 -1) r(2 2) U6
< X-CDN: Incapsula
<
* Connection #0 to host www.bitstamp.net left intact
result: 0
response:
terminate called after throwing an instance of 'std::runtime_error'
what(): Bitstamp response doesn't contain result data
Any idea ?
Thanks a lot in advance !
Initially I had the balance path to be /balance, but after changing to /balance/ it worked and got 200 back with payload.
So instead of http://www.bitstamp.net/api/v2/balance use http://www.bitstamp.net/api/v2/balance/, note the trailing backslash

PayPal REST API: trying to activate a billing plan, but getting "HTTP/1.1 401 Unauthorized"

I am building an EC site, where my customers can pay through PayPal API. Now, I am learning how it works, using Sandbox; referring to this page: https://developer.paypal.com/docs/integration/direct/billing-plans/
I have succeeded the prerequisites, i.e., having created a PayPal app,
gotten an access token, and made an API call. And then, I have succeeded making a billing plan, copying-and-pasting the sample command on the page, just replacing the Access Token.
Now, I want to activate the billing plan, but couldn't have succeeded.
The command used is, once again, copied-and-pasted from the page, as below.
curl -v -k -X PATCH https://api.sandbox.paypal.com/v1/payments/billing-plans/P-7DC96732KA7763723UOPKETA/ \
-H 'X-PAYPAL-OAUTH-CONTEXT: {"consumer":{"accountNumber":1181198218909172527,"merchantId":"5KW8F2FXKX5HA"},"merchant":{"accountNumber":1659371090107732880,"merchantId":"2J6QB8YJQSJRJ"},"apiCaller":{"clientId":"AdtlNBDhgmQWi2xk6edqJVKklPFyDWxtyKuXuyVT-OgdnnKpAVsbKHgvqHHP","appId":"APP-6DV794347V142302B","payerId":"2J6QB8YJQSJRJ","accountNumber":"1659371090107732880"},"scopes":["https://api.paypal.com/v1/payments/.*","https://uri.paypal.com/services/payments/futurepayments","openid"]}' \
-H 'Content-Type: application/json' \
-d '[{
"op": "replace",
"path": "/",
"value": {
"state": "ACTIVE"
}
}]'
First, as instructed, I just replaced the Plan ID "P-7DC96732KA7763723UOPKETA" with mine, provided in the previous response for creating the plan.
* Trying 173.0.82.78...
* Connected to api.sandbox.paypal.com (173.0.82.78) port 443 (#0)
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_CBC_SHA256
* Server certificate: api.sandbox.paypal.com
* Server certificate: Symantec Class 3 Secure Server CA - G4
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5
> PATCH /v1/payments/billing-plans/P-8AX21799EN516221GJMBOECA/ HTTP/1.1
> Host: api.sandbox.paypal.com
> User-Agent: curl/7.43.0
> Accept: */*
> X-PAYPAL-OAUTH-CONTEXT: {"consumer":{"accountNumber":1181198218909172527,"merchantId":"5KW8F2FXKX5HA"},"merchant":{"accountNumber":1659371090107732880,"merchantId":"2J6QB8YJQSJRJ"},"apiCaller":{"clientId":"AdtlNBDhgmQWi2xk6edqJVKklPFyDWxtyKuXuyVT-OgdnnKpAVsbKHgvqHHP","appId":"APP-6DV794347V142302B","payerId":"2J6QB8YJQSJRJ","accountNumber":"1659371090107732880"},"scopes":["ttps://api.paypal.com/v1/payments/.*","ttps://uri.paypal.com/services/payments/futurepayments","openid"]}
> Content-Type: application/json
> Content-Length: 78
>
* upload completely sent off: 78 out of 78 bytes
< HTTP/1.1 401 Unauthorized
< Date: Fri, 17 Feb 2017 12:18:47 GMT
< Server: Apache
< paypal-debug-id: c46e304b4bb46
< Paypal-Debug-Id: c46e304b4bb46
< Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dplatformapiserv%26TIME%3D669689432%26HTTP_X_PP_AZ_LOCATOR%3D; Expires=Fri, 17 Feb 2017 12:48:47 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
< Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
< Content-Length: 0
< Connection: close
< Content-Type: text/plain; charset=ISO-8859-1
<
* Closing connection 0
And I tried with some other parameter replacements, like the Client ID, but no luck.
Do I need to replace other parameters?
Or, have I done something wrong?
SOLVED.
On this page, I found simpler and more straightforward command
and made up below:
curl -v -X PATCH https://api.sandbox.paypal.com/v1/payments/billing-plans/<Plan ID>/ \
-H "Content-Type:application/json" \
-H "Authorization: Bearer <Access Token>" \
-d '[
{
"path":"/",
"value":{"state":"ACTIVE"},
"op":"replace"}
]'
Got the response as below:
* Trying 173.0.82.78...
* Connected to api.sandbox.paypal.com (173.0.82.78) port 443 (#0)
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_CBC_SHA256
* Server certificate: api.sandbox.paypal.com
* Server certificate: Symantec Class 3 Secure Server CA - G4
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5
> GET /v1/payments/billing-plans/<Plan ID> HTTP/1.1
> Host: api.sandbox.paypal.com
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type:application/json
> Authorization: Bearer <Access Token>
>
< HTTP/1.1 200 OK
< Date: Sun, 19 Feb 2017 11:36:50 GMT
< Server: Apache
< paypal-debug-id: 3ca31778e271e
< Content-Language: *
< Paypal-Debug-Id: 3ca31778e271e
< Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dplatformapiserv%26TIME%3D1384360280%26HTTP_X_PP_AZ_LOCATOR%3D; Expires=Sun, 19 Feb 2017 12:06:52 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
< Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
< Vary: Authorization
< Content-Length: 1391
< Connection: close
< Content-Type: application/json
<
* Closing connection 0
{"id":"<Plan ID>","state":"ACTIVE","name":"Sample Plan",
...
"rel":"self","method":"GET"}]}
Got HTTP 200 and the state "ACTIVE".
Thanks for your trying to help, many thanks!

Error in Basic-Authentication Login (406 Not Acceptable)

After implementing Basic-Authentication for my Jersey REST services, I'm implementing Authentication for my Client API using HTTPBasicAuthFilter.
I'm using Glassfish 3.1.2 and NetBeans.
I've followed the code written in http://javaevangelist.blogspot.pt/2012/07/jax-rs-tip-of-day-basic-client_27.html, and just changed the following parameters:
erc.setUsernamePassword("blive2", "microio") - this is the correct login
private static final String BASE_URI = "http://localhost:8080/LULServices/webresources"
webResource = client.resource(BASE_URI).path("entities.user")
So, when I run this file, the following message appears:
Mar 11, 2013 5:30:38 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client out-bound request
1 > GET http://localhost:8080/LULServices/webresources/entities.user
1 > Accept: text/plain
1 > Authorization: Basic YmxpdmUyOm1pY3JvaW8=
Mar 11, 2013 5:30:38 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client in-bound response
1 < 406
1 < Date: Mon, 11 Mar 2013 17:30:38 GMT
1 < Content-Length: 1231
1 < Expires: Thu, 01 Jan 1970 01:00:00 GMT
1 < Content-Type: text/html
1 < Server: GlassFish Server Open Source Edition 3.1.2.2
1 < X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
1 < Cache-Control: no-cache
1 < Pragma: No-cache
1 <
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>GlassFish Server Open Source Edition 3.1.2.2 - Error report</title><style type="text/css"><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 406 - Not Acceptable</h1><hr/><p><b>type</b> Status report</p><p><b>message</b>Not Acceptable</p><p><b>description</b>The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers (Not Acceptable).</p><hr/><h3>GlassFish Server Open Source Edition 3.1.2.2</h3></body></html>
Exception in thread "main" com.sun.jersey.api.client.UniformInterfaceException: GET http://localhost:8080/LULServices/webresources/entities.user returned a response status of 406 Not Acceptable
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:686)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:507)
at lulClient.BasicAuthenticationClient$ExampleResourceClient.getMessage(BasicAuthenticationClient.java:38)
at lulClient.BasicAuthenticationClient.main(BasicAuthenticationClient.java:19)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
So it is the 406 Not Acceptable that appears.
Can you help me to solve it?
Thanks!
The problem is solved. The information I was asking to the service was just returned in two types: APPLICATION_JSON, or APPLICATION_XML. So I had to alter the part of the code where I inserted the type to:
javax.ws.rs.core.MediaType.APPLICATION_JSON or javax.ws.rs.core.MediaType.APPLICATION_XML.