|
![Picture of Melanie Wehowski Picture of Melanie Wehowski](/picture/user/948304.jpg) Melanie Wehowski - 2013-11-20 19:51:19
Hi Manuel,
thank you for this great work!
I bag you for help:
The facebook example is not working:
[code]
<?php
/*
* login_with_facebook.php
*
* @(#) $Id: login_with_facebook.php,v 1.3 2013/07/31 11:48:04 mlemos Exp $
*
*/
/*
* Get the http.php file from http://www.phpclasses.org/httpclient
require('http.php');
require('oauth_client.php');
*/
require('mainfile.php');
$client = new oauth_client_class;
$client->debug = true;
$client->debug_http = true;
$client->server = 'Facebook';
$client->redirect_uri = 'http://xxxx/login_with_facebook.php';
$client->client_id = 'xxx'; $application_line = __LINE__;
$client->client_secret = 'xxx';
//added this but does not help:
$client->api_key = 'xxx';
if(strlen($client->client_id) == 0
|| strlen($client->client_secret) == 0)
die('Please go to Facebook Apps page https://developers.facebook.com/apps , '.
'create an application, and in the line '.$application_line.
' set the client_id to App ID/API Key and client_secret with App Secret');
/* API permissions
*/
$client->scope = 'email';
if(($success = $client->Initialize()))
{
if(($success = $client->Process()))
{
if(strlen($client->access_token))
{
$success = $client->CallAPI(
'https://graph.facebook.com/me/',
'GET', array(), array('FailOnAccessError'=>true), $user);
}
}
$success = $client->Finalize($success);
}
if($client->exit)exit;
//debug
$userdata = mxGetUserData();
if($userdata['uname'] === 'webfan')
{
var_dump($client);
//die();
}
if($success)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Facebook OAuth client results</title>
</head>
<body>
<?php
echo '<h1>', HtmlSpecialChars($user->name),
' you have logged in successfully with Facebook!</h1>';
echo '<pre>', HtmlSpecialChars(print_r($user, 1)), '</pre>';
?>
</body>
</html>
<?php
}
else
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>OAuth client error</title>
</head>
<body>
<h1>OAuth client error</h1>
<pre>Error: <?php echo HtmlSpecialChars($client->error); ?></pre>
</body>
</html>
<?php
}
?>
[/code]
The result:
[code]
object(oauth_client_class)#2 (38) { ["error"]=> string(110)
"it was not possible to open the OAuth access token URL: 110 could not connect to the host
"graph.facebook.com"" ["debug"]=> bool(true) ["debug_http"]=> bool(true) ["exit"]=> bool(false)
["debug_output"]=> string(826) "OAuth client: Checking if OAuth access token was already retrieved
from https://graph.facebook.com/oauth/access_token OAuth client: Checking the authentication state
in URI /login_with_facebook.php?code=xxx&state=1384969311-fa028e
OAuth client: Checking the authentication code OAuth client:
Accessing the OAuth access token at https://graph.facebook.com/oauth/access_token
OAuth client: Error: it was not possible to open the OAuth access token URL: 110 could not connect to the host "graph.facebook.com" "
["debug_prefix"]=> string(14) "OAuth client: "
["server"]=> string(8) "Facebook" ["request_token_url"]=> string(0) ""
["dialog_url"]=> string(115) "https://www.facebook.com/dialog/oauth?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}&state={STATE}"
["offline_dialog_url"]=> string(0) "" ["append_state_to_redirect_uri"]=> string(0) ""
["access_token_url"]=> string(45) "https://graph.facebook.com/oauth/access_token"
["oauth_version"]=> string(3) "2.0" ["url_parameters"]=> bool(false)
["authorization_header"]=> bool(true) ["token_request_method"]=> string(3) "GET"
["signature_method"]=> string(9) "HMAC-SHA1" ["redirect_uri"]=> string(43) "http://xxx/login_with_facebook.php"
["client_id"]=> string(15) "xxx" ["client_secret"]=> string(32) "xxx"
["api_key"]=> string(32) "xxx" ["get_token_with_api_key"]=> bool(false)
["scope"]=> string(5) "email" ["offline"]=> bool(false) ["access_token"]=> string(0) ""
["access_token_secret"]=> string(0) "" ["access_token_expiry"]=> string(0) ""
["access_token_type"]=> string(0) "" ["default_access_token_type"]=> string(0) ""
["access_token_parameter"]=> string(0) "" ["access_token_response"]=> NULL
["store_access_token_response"]=> bool(false) ["refresh_token"]=> string(0) ""
["access_token_error"]=> string(0) "" ["authorization_error"]=> string(0) ""
["response_status"]=> int(0) ["oauth_user_agent"]=> string(25) "schmeckts.at OAuth Client"
["session_started"]=> bool(true) }
OAuth client error
Error: it was not possible to open the OAuth access token URL: 110 could not connect to the host "graph.facebook.com"
[/code]
The Client-Id and secret should be setup ok and was replaces by xxx in the above example.
I would be happy about a hint, thank you!
regards,
Till
![Picture of Melanie Wehowski Picture of Melanie Wehowski](/picture/user/948304.jpg) Melanie Wehowski - 2013-11-20 21:42:37 - In reply to message 1 from Melanie Wehowski
Its thrown by class http_class? But why?
Could there a problem with the webhost?
![Picture of Melanie Wehowski Picture of Melanie Wehowski](/picture/user/948304.jpg) Melanie Wehowski - 2013-11-20 23:00:55 - In reply to message 2 from Melanie Wehowski
Ok, I figured it out, thread solved, thank you!
The customers host just has wrong allow_url_fopen settings,
on my own server erverything is working fine!
regards,
Till
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2013-11-20 23:06:36 - In reply to message 3 from Melanie Wehowski
The error means that Facebook server was not accepting connections. Could be a temporary thing. I do not thing that allow_url_fopen would cause that.
![Picture of Melanie Wehowski Picture of Melanie Wehowski](/picture/user/948304.jpg) Melanie Wehowski - 2013-11-20 23:49:06 - In reply to message 4 from Manuel Lemos
Mh?
The error message is:
Error: it was not possible to open the OAuth access token URL: 110 could not connect to the host "graph.facebook.com"
I think the error is thrown in http_class line 435,
the fsockopen is not working? (maybe not allow_url_fopen?)
When I copied evrything to another server and just changed the Url in facebook is was working, back to the other server its not working again.
The request on the error server is taking a long time until it prints the error.
regards,
Till
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2013-11-21 01:25:24 - In reply to message 5 from Melanie Wehowski
That is a sympthom that there is a firewall in that server blocking outgoing connections. 110 is a OS level error for refused connections. If it was a PHP configuration issue, it would not take time to return the error. The time it takes to return the error is the connection timeout period.
![Picture of Melanie Wehowski Picture of Melanie Wehowski](/picture/user/948304.jpg) Melanie Wehowski - 2013-11-21 01:41:34 - In reply to message 6 from Manuel Lemos
Ok, I had a similar issue cUrl enabled but not working on this server.
I will give this information to the customer and his administrator.
Thank you very much Manuel!
regards,
Till
![Picture of Melanie Wehowski Picture of Melanie Wehowski](/picture/user/948304.jpg) Melanie Wehowski - 2013-11-21 02:02:17 - In reply to message 7 from Melanie Wehowski
...
this class:
phpclasses.org/package/7123-PHP-Sen ...
using stream_context_create seems to work on this host...
I will wait for administrators answer and continue tomorrow...
regard,
Till
![Picture of Melanie Wehowski Picture of Melanie Wehowski](/picture/user/948304.jpg) Melanie Wehowski - 2013-11-21 19:35:02 - In reply to message 8 from Melanie Wehowski
The Server-Admin solved the problem.
Thank you!
regards,
Till
|