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.
Related
Is there any way using AWS Cognito to send the user their verification code, have them enter the code, verify it is a valid code, THEN have them set their username and password?
For some reason, the workflow in my mind seems strange for the user to enter their code and new password in the same step. I want to check their code, and if it is valid, then take them to the screen to reset their password.
So far I've used the API function call:
forgotPassword
To send the code, which works fine, and from all my reading of the docs and searching here and online, I see that the next step is to call:
confirmForgotPassword
But in this step, it requires the new password (from what I can tell from the documentation):
$result = $client->confirmForgotPassword([
'AnalyticsMetadata' => [
'AnalyticsEndpointId' => '<string>',
],
'ClientId' => '<string>', // REQUIRED
'ClientMetadata' => ['<string>', ...],
'ConfirmationCode' => '<string>', // REQUIRED
'Password' => '<string>', // REQUIRED
'SecretHash' => '<string>',
'UserContextData' => [
'EncodedData' => '<string>',
],
'Username' => '<string>', // REQUIRED
]);
Am I missing something?
For context, I'm using the PHP API, but I'm really just looking for the correct API calls in the correct order to accomplish what I'd like if it is even possible.
Thanks in advance.
I changed my workflow so that I used a lambda function in AWS to send a link with the code, this way I validate the code on the link click and then the user can enter their password in.
Doesn't seem possible to do this in two steps.
What I am actually trying to do is to retrieve my posts/statuses from my personal facebook profile page (this is not a fan page) and display them in my website. Also please note that every user that will visit my website should be able to view my statuses by means it does not have to do with authenticating them or something like that. This is something that needs to be generated server-side.
I am aware that you can retrieve a JSON string from a URL like this https://graph.facebook.com/MY_PROFILE_ID/feed?access_token=ACCESS_TOKEN because I tried it from the facebook developers (Graph API Explorer) page and it is exactly what I need.
The thing is that when I generate the access token from the Graph API Explorer I can select permissions and it generates the token respectively according to permissions chosen, such as user_status, status_update, etc.
Now I want to accomplish this by using PHP-SDK but I have no idea how to generate an access token the same as the one I generate in the Graph API Explorer.
The basic way to do this is by calling getAccessToken() as shown here. The thing is that when I use the token generated from this simple method the JSON string returned will only show me my basic information.
$config = array(
'appId' => 'MY_APP_ID',
'secret' => 'MY_APP_SECRET',
);
$facebook = new Facebook($config);
$ACCESS_TOKEN = $facebook->getAccessToken();
How can I add permissions for instance? Should I assign parameters somewhere? I spent quite a lot of time reading the facebook API documentation and some other forums but I did not find the answer that I need.
Finally if I get the right access token than I would simply retrieve the JSON string and parse it with what I need.
Thanks.
you need for add permissions in your code for login using the fb js sdk add in the scope this like this example:
$("#login").on('click',function(){
FB.login(function(response){
console.log(response);
},{scope: 'email,manage_pages,read_insights'});
});
or in php fb sdk the next form:
<?php
require 'server/fb-php-sdk/facebook.php';
$app_id = 'APP_ID';
$app_secret = 'APP_SECRET';
$app_namespace = 'APP_NAMESPACE';
$app_url = 'https://apps.facebook.com/' . $app_namespace . '/';
$scope = 'email,publish_actions';
// Init the Facebook SDK
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
// Get the current user
$user = $facebook->getUser();
// If the user has not installed the app, redirect them to the Login Dialog
if (!$user) {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => $scope,
'redirect_uri' => $app_url,
));
print('<script> top.location.href=\'' . $loginUrl . '\'</script>');
}
?>
the most important for add permission is this part :
$scope = 'email,publish_actions';
you can find all about the extended permissions in this link
https://developers.facebook.com/docs/reference/login/extended-permissions
In my javascript I have a click event that triggers an ajax call to the php page where I send my notification from. I chose to do it this way because the documentation advises against using your app secret in any client side code, and the notifications parameters requires an access token that you can only get using the app secret.
The problem I'm having is that even though I'm logged in, $facebook->getUser() is returning 0 in php, so the api call I make afterwards to send the notification wont work. My user is already logged in via the client side code, so how do I get the message to the php that they're logged in so the notification can be sent.
//JS
$.ajax({
url : "http://xxxxxo/bn/notification.php",
type : 'POST',
data: {notify: notify },
success : function (result) {
console.log(result);
},
error : function () {
alert("error sending notification");
}
});//closes ajax
//PHP
<?php
require_once(dirname(__FILE__).'/php-sdk/facebook.php') ;
$APPLICATION_ID = '1402xxxxx7';
$APPLICATION_SECRET = 'ce71d6bbxxxxx5f55a';
$fb_app_url = "http://apps.facebook.com/myAPP";
$config = array();
$config['appId'] = $APP_ID;
$config['secret'] = $APP_SECRET;
$config['cookie'] = true;
$facebook = new Facebook($config) or die('Error is here!');
$facebook = new Facebook(array(
'appId' => $APP_ID,
'secret' => $APP_SECRET,
'fileUpload' => true
));
$notify = $_REQUEST['notify'];
$userid = $facebook->getUser();
/*IF WE HAVE A LOGGED IN USER AND THE 'NOTIFY' REQUEST VALUE, THEN SEND THE NOTIFICATION.
BUT MY USER ID IS 0. HOW DO I GET PHP TO RECOGNIZE ME AS LOGGED IN WITHOUT HAVING TO FORCE MY USER TO LOG IN VIA PHP AFTER THEY'VE ALREADY LOGGED IN CLIENT SIDE?*/
if($userid && $notify){
$token_url ="https://graph.facebook.com/oauth/access_token?" .
"client_id=" . $APP_ID .
"&client_secret=" . $APP_SECRET .
"&grant_type=client_credentials";
$app_token = file_get_contents($token_url);
$app_token = str_replace("access_token=", "", $app_token);
$data = array(
'href'=> 'https://apps.facebook.com/thebringernetwork/',
'access_token'=> $app_token,
'template'=> 'test'
);
$sendnotification = $facebook->api('/1622649653/notifications', 'post', $data);
}else{
//handle error
}
?>
The first thing I noticed is that you define your app id as $APPLICATION_ID but use it as $APP_ID (and the same goes for your app secret). But since you didn't mention any errors and $facebook->getUser(); executes I'm guessing this is just a bad copy-paste.
Now for the sake of answering this question I'm going to presume that you are using the latest versions of both JS and PHP SDKs. These use oauth 2.0 and change the way you pass the login information from JS to PHP.
According to Facebook Developer Blog removing $config['cookie'] = true; and setting oauth to true in your JS configuration should work. Just make sure to refresh the site after the login.
The solution I've found in my own project is to disable cookies altogether and simply pass the access token to my PHP script.
In your JS call your PHP script like this (make sure to call this after the JS login!):
$.ajax({
url : "http://xxxxxo/bn/notification.php",
type : 'POST',
data: {
notify: notify,
token: FB.getAuthResponse()['accessToken'] // add your access token
},
success : function (result) {
console.log(result);
},
error : function () {
alert("error sending notification");
}
});
And in your PHP script add this after creating the FB object.
$facebook->setAccessToken($_POST['token']); // set the users access token
Doing things this way will also get rid of any need to refresh the website after the login.
Yes, this is a common problem when using the PHP SDK in combination with AJAX:
When you make an AJAX request, the PHP SDK deletes the cookies where the authorization information are stored, and then the next call to getUser will just return 0, because this method tries to find the current user id in those cookies – apparently there is something in the OAuth 2.0 spec that demands this behavior to prevent some sort of click-jacking attack.
But the info will still be stored in the session, so you can read the user id (and the user access token, should you need it) from there:
$user_id = $_SESSION['fb_YourAppIdHere_user_id'];
$user_access_token = $_SESSION['fb_YourAppIdHere_access_token'];
Replace YourAppIdHere with your app id (so it becomes fb_1234567890_user_id resp. fb_1234567890_access_token) to get the correct names of those session keys.
At the moment I have to download images on the server and post them like this:
$photo = array(
'message' => 'Status',
'source' => '#/full/path/of/the/image.png'
);
$response = $fb->api('/'.$album.'/photos', 'POST', $photo);
I'm using curl on the backend to post this request and it's working like a charm.
I'm wondering if it's possible to post the remote image directly instead to download a local copy?
I tried to do something like this:
$photo = array(
'message' => 'Status',
'source' => file_get_contents('http://www.domain.com/image.png')
);
$response = $fb->api('/'.$album.'/photos', 'POST', $photo);
But I got an exception from the graph API: "(#324) Requires upload file"
It looks like this is happening when you are not sending the multipart/data header which is set automatically when sending an array of data ($data is an array).
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
So I'm doubtful that it's possible to post a remote image.
What do you think?
It is possible to upload a photo by just giving that photo’s URL under the parameter name url.
This info is a little hidden in the description of the photo endpoint, where it just says,
“You can also publish a photo by providing a url param with the photo's URL.”
So instead of providing the sourceparameter, just provide url with the value of the photo’s publicly reachable URL. (All other parameters except source stay the same and are still usable in the same way.)
I tried this recently, and it worked fine. Although, I only tried it for photos with URLs from my app domain – I can’t say for sure if it works for URLs from “anywhere” on the web as well (although i can’t see a good reason for why it shouldn’t).
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.