get content from facebook url using php - facebook-graph-api

How to get content from facebook url and extract facebook user id and access token. I have used CURL and it's returning empty content.
$url = 'https://graph.facebook.com/oauth/access_token?client_id='.$fbconfig['appid'].'&redirect_uri='.$returnurl.'&client_secret='.$fbconfig['secret'].'&code='.$_REQUEST['code'];
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_VERBOSE => true
));
$result = curl_exec($ch);
curl_close($ch);
$iResult=AlowUserAccess();
$FBUserId = explode('|', $iResult);
$FBUserId = explode('|', $FBUserId['1']);
$FBUserId = explode('-', $FBUserId['0']);
$iUserId = $FBUserId['1'];
$iUserId = $iResult;
$sAccessToken = explode('access_token=', $iResult);

Try using the options used here:
PHP script to automate login and form submit
Your not setting both SSL opts, it is also possible they may want to set a cookie.

Related

How authenticate listclients request

I try to get from PHP the information about the currently connected clients.
http://10.0.0.2:8000/admin/listclients?mount=/stream.mpeg
but this required an authenfication, which is not possible from a program. So I tried
http://10.0.0.2:8000/admin/listclients?mount=/stream.mpeg&user=xyz&pass=wert
but Icecast does not accept the user and pass. If I do it inside a browser it works?
In which way I have to provide user and pass?
Or is some additional information required?
Google did not help me.
It's not possible to put user and pass directlyin the URL. These information has to be base64 encoded and put into the header. Below you find a php example:
$url = "http://www.domain.eu:80004/admin/listclients?mount=/stream.mpeg";
$user = "source";
$pass= "password";
$opts = array('http' =>
array(
'method' => 'GET',
'header' => array ('Authorization: Basic '.base64_encode("$user:$pass"))
)
);
$context = stream_context_create($opts);
$list1 = file_get_contents($url1, false, $context);
You can use the admin password or the source password. I the example I have used the source password.

Reading from the response stream reached the inactivity timeout

trying to implement REST API oauth2.0 authentification with symfony4.
The road /oauth/v2/token works well but, i'm trying to create /api/login road that will get credentials from the request and make a Httpclient->request() to /oauth/v2/token and get the access token and return to the user.
This is my code :
public function login(Request $request)
{
//dd($request->getMethod());
$method = $request->getMethod();
$grantType = $request->query->get('grant_type');
$clientId = $request->query->get('client_id');
$secretId = $request->query->get('client_secret');
$username = $request->query->get('username');
$password = $request->query->get('password');
$path = $_SERVER['API_BASE_URL'] . 'oauth/v2/token';
$httpClient = HttpClient::create();
//dd($httpClient);
$response = $httpClient->request($method, $path, [
// these values are automatically encoded before including them in the URL
'query' => [
'grant_type' => $grantType,
'client_id' => $clientId,
'client_secret' => $secretId,
'username' => $username,
'password' => $password,
],
]);
$statusCode = $response->getStatusCode();
$contentType = $response->getHeaders()['content-type'][0];
$content = $response->getContent();
$content = $response->toArray();
return $content;
}
But i'm getting this error since and i'm unable to solve :
{"error":{"code":500,"message":"Internal Server Error","exception":[{"message":"Reading from the response stream reached the inactivity timeout.","class":"Symfony\\Component\\HttpClient\\Exception\\TransportException","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"D:\\vendor\\symfony\\http-client\\Chunk\\ErrorChunk.php","line":105,"args":[]},{"namespace":"Symfony\\Component\\HttpClient\\Chunk","short_class":"ErrorChunk","class":"Symfony\\Component\\HttpClient\\Chunk\\ErrorChunk","type":"->","function":"__destruct","file":"\\vendor\\symfony\\http-client\\Response\\CurlResponse.php","line":121,"args":[]},{"namespace":"Symfony\\Component\\HttpClient\\Response","short_class":"CurlResponse","class":"Symfony\\Component\\HttpClient\\Response\\CurlResponse","type":"::","function":"Symfony\\Component\\HttpClient\\Response\\{closure}","file":"\\vendor\\symfony\\http-client\\Response\\ResponseTrait.php","line":67,"args":[["object","Symfony\\Component\\HttpClient\\Response\\CurlResponse"]]},{"namespace":"Symfony\\Component\\HttpClient\\Response","short_class":"CurlResponse","class":"Symfony\\Component\\HttpClient\\Response\\CurlResponse","type":"->","function":"getStatusCode","file":"\\src\\Controller\\RestApiController.php","line":121,"args":[]},{"namespace":"App\\Controller","short_class":"RestApiController","class":"App\\Controller\\RestApiController","type":"->","function":"login","file":"D:\\Binghana\\new\\goldwin-website\\vendor\\symfony\\http-kernel\\HttpKernel.php","line":150,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"]]},{"namespace":"Symfony\\Component\\HttpKernel","short_class":"HttpKernel","class":"Symfony\\Component\\HttpKernel\\HttpKernel","type":"->","function":"handleRaw","file":"\\vendor\\symfony\\http-kernel\\HttpKernel.php","line":67,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"],["integer",1]]},{"namespace":"Symfony\\Component\\HttpKernel","short_class":"HttpKernel","class":"Symfony\\Component\\HttpKernel\\HttpKernel","type":"->","function":"handle","file":"D:\\Binghana\\new\\goldwin-website\\vendor\\symfony\\http-kernel\\Kernel.php","line":198,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"],["integer",1],["boolean",true]]},{"namespace":"Symfony\\Component\\HttpKernel","short_class":"Kernel","class":"Symfony\\Component\\HttpKernel\\Kernel","type":"->","function":"handle","file":"D:\\Binghana\\new\\goldwin-website\\public\\index.php","line":25,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"]]}]}]}}
I have tried updating httpclient version, even using Guzzle, same error.

Prestashop api - creating order history doesn't send e-mail

I'm trying to add order history (and change order_state with that) by using prestashop api:
$xml = $this->api->get(array('url' => $url . '/api/order_histories?schema=blank'));
$xml->order_history->id_order_state = 4;
$xml->order_history->id_order = $order_id;
unset( $xml->order_history->id );
unset( $xml->order_history->date_add );
$xml = $this->api->add(array(
'resource' => 'order_histories',
'postXml' => $xml->asXML()
));
It works just fine (order_state is changed) but presta doesn't sending any notification to buyer.
Set this line:
'resource' => 'order_histories',
To this:
'resource' => 'order_histories?sendemail=1',

Adding a tab to a fan page does not work... error: (#210) Subject must be a page

I'm trying to add a tab to a fanpage using the graph api/PHP SDK and I'm receiving an error :
(#210) Subject must be a page I've tried using both the user access_token AND the page access_token but neither work. I've tried using the page id of numerous accounts and still no go. Here is my code:
<?php
$path="/PAGE_ID/tabs/";
$access_token="ACCESS_TOKEN";
$params = array(
'app_id' => "APP_ID",
'access_token' => $access_token
);
try{
$install = $facebook->api($path, "POST", $params);
}catch (FacebookApiException $o){
print_r($o);
}
?>
And here is the error I get:
FacebookApiException Object
(
[result:protected] => Array
(
[error] => Array
(
[message] => (#210) Subject must be a page.
[type] => OAuthException
)
)
[message:protected] => (#210) Subject must be a page.
[string:Exception:private] =>
[code:protected] => 0
Thanks for any help you can provide!
If you are not limited to using the API to add your application to your page then you can follow the instructions provided by Facebook at this link :
https://developers.facebook.com/docs/reference/dialogs/add_to_page/
Essentially you can use a dialog ( see the link above ) or this direct URL to add tab apps to your page :
https://www.facebook.com/dialog/pagetab?app_id=YOUR_APP_ID&display=popup&next=YOUR_URL
Dont forget to substitute APP_ID for your app id and next for a different URL
API Call is atm bugged: https://developers.connect.facebook.com/bugs/149252845187252?browse=search_4f31da351c4870e34879109
But here is a solution for JS: OAuthException "(#210) Subject must be a page." - just do not use the library and do your own call.
I did it with PHP:
<?php
$url = 'https://graph.facebook.com/<PAGE ID>/tabs?app_id=<APP ID>&method=POST&access_token=<PAGE ACCESS TOKEN>&callback=test';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
Echo value should be something like "test(true)".

card code is not validating in authorize.net

I am developing a web application. Here I have implemented the authorize.net payment gateway.
But here the cave code is not validating correctly. If I give wrong card code the payment results in success But i need the result as payment declained
Does anyone know this?
see the code
"x_version" => "3.1",
"x_delim_data" => "TRUE",
"x_delim_char" => "|",
"x_relay_response" => "FALSE",
"x_type" => "AUTH_CAPTURE",
"x_method" => "CC",
"x_card_num" => $card_number,
"x_exp_date" => $exp_date,
"x_amount" => $amount,
"x_description" => "Live Transaction",
"x_card_code" => $ccv,
"x_first_name" => $bill_name,
"x_address" => $bill_address,
"x_city" => $bill_city,
"x_state" => $bill_state,
"x_zip" => $bill_zip,
"x_country" => $bill_country,
"x_phone" => $bill_phone,
"x_email" => $email,
"x_ship_to_first_name" => $ship_name,
"x_ship_to_address" => $ship_address,
"x_ship_to_city" => $ship_city,
"x_ship_to_state" => $ship_state,
"x_ship_to_zip" => $ship_zip,
"x_ship_to_country" => $ship_country,
"x_ship_to_phone" => $ship_phone
// Additional fields can be added here as outlined in the AIM integration
// guide at: http://developer.authorize.net
);
// This section takes the input fields and converts them to the proper format
// for an http post. For example: "x_login=username&x_tran_key=a1B2c3D4"
$post_string = "";
foreach( $post_values as $key => $value )
{ $post_string .= "$key=" . urlencode( $value ) . "&"; }
$post_string = rtrim( $post_string, "& " );
// The following section provides an example of how to add line item details to
// the post string. Because line items may consist of multiple values with the
// same key/name, they cannot be simply added into the above array.
//
// This section is commented out by default.
foreach( $line_items as $value )
{ $post_string .= "&x_line_item=" . urlencode( $value ); }
// This sample code uses the CURL library for php to establish a connection,
// submit the post, and record the response.
// If you receive an error, you may want to ensure that you have the curl
// library enabled in your php configuration
$request = curl_init($post_url); // initiate curl object
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
$post_response = curl_exec($request); // execute curl post and store results in $post_response
// additional options may be required depending upon your server configuration
// you can find documentation on curl options at http://www.php.net/curl_setopt
curl_close ($request); // close curl object
// This line takes the response and breaks it into an array using the specified delimiting character
$response_array = explode($post_values["x_delim_char"],$post_response);
You problem might be related to some incorrect settings in the authorize.net account. Check the following:
Make sure that the transaction version is set to 3.1. You can do that from Settings->Transaction Version->Submit
Set the Card Code Verification rejection settings and select N and U options. To do that, go to Settings->Card Code Verification
Make sure that the x_version field is set to "3.1" and that the x_card_code contains CCV number.
Hope this helps.
More details:
https://support.authorize.net/authkb/index?page=content&id=A546&impressions=false
It's not a code error. If you want the payment to be declined when the CVV number is incorrect you need to set it in your Authorize.Net control panel. It is found under the security settings.