Unable to read or post to friends wall (news feed) - php

I have been trying to read a friends news feed to check if my message is there (does not matter if the message is visible, hidden or deleted) and if the message is there, not to post a new message. If it is not there than post a message. The code is below with a lot of unnecessary code to trace where the problem was coming from. I have my permission set for 'publish_stream, read_stream'.
I tried all the code in the other blogs but non seemed to work I do not know whether it is because I am using PHP SDK 3.0 - latest version. My App is iframe app. Even bought an expensive book (too expensive) on Facebook Applications but found out, after buying, that it was out of date!
The code works well if I am using /me or my user id but not my friend's id.
require 'config.php';
require 'facebook.php';
//Create facebook application instance.
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret
));
$sent = false;
$userData = null;
$PPnotposted = true;
$me = null;
$test_friends =1;
$user = $facebook->getUser();
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl(array("next"=> "<? echo $fb_app_url ?>" ));
} else {
$loginUrl = $facebook->getLoginUrl( array( 'scope'=> 'publish_stream, read_stream', 'redirect_uri' => $fb_app_url));
}
$get_someone_else = 100000xxxxxxxxx; // I used a real user id but covered it up here so
my friend's id hidden for this stackexchange help
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
if ( $get_someone_else ){
$user_profile = $facebook->api("/".$get_someone_else);
echo "<br/> ********************user is ".$get_someone_else." ******************<br/>";
var_dump( $user_profile );
echo "<br/> ********************** end of user info ******************<br/>";
} else {
$user_profile = $facebook->api('/me');
}
} catch (FacebookApiException $e) {
}
// print_r( $user_profile );
$PPaccesstoken = $facebook->getAccessToken();
$attachment[access_token]= $PPaccesstoken ;
//post message to wall if it is sent through form
if(isset($_POST['PPmessage'])){
try {
if( $get_someone_else ){
$ppmy_news = $facebook->api("/.$get_someone_else./feed?limit=300"); //Get 300 messages to examine
echo "<br/> *********************** news feed is ".$ppmy_news." ******************<br/>";
var_dump( $ppmy_news );
echo "<br/> ******************** end of user info ********************<br/>";
} else {
$ppmy_news = $facebook->api('/me/feed?limit=300'); //Get 300 messages
//to examine. Initially I set it to
// 10 messages for testing purposes.
}
// var_dump( $ppmy_news);
// $sent = $facebook->api("/".$user."/feed", 'POST', $attachment );
$ppmy_view_lp=0;
if( $test_friends ) { //Debugging flag to activate or deactivate parts of code
echo "sent is :<br />";
// var_dump( $sent );
echo "<br />";
$friends = $facebook->api('/me/friends');
echo "friends is :<br />";
// var_dump( $friends );
echo "<br />";
$friendsLists = $facebook->api('/me/friends');
$total_friends = 0;
foreach ($friendsLists as $friends) {
foreach ($friends as $friend) {
$id = $friend['id'];
$name = $friend['name'];
$total_friends++; //Get total number of friends
echo "friend : ".$name." id is: ".$id." Total friends is : ".$total_friends." <br/> ";
}
}
}
} catch (FacebookApiException $e) {
echo "<br/> !!!!!!!!!!!! Error Dump Line 85 !!!!!!!!!!!!! <br/>";
var_dump( $e );
echo "<br/> !!!!!!!!!!!! End of Error Dump !!!!!!!!!!!!! <br/>";
//do something about it
}
}
}
But I find I am denied permission and the catch dump is:
!!!!!!!!!!!! Error Dump Line 85 !!!!!!!!!!!!!
object(FacebookApiException)#2 (7) { ["result:protected"]=> array(1) { ["error"]=> array(3) { ["message"]=> string(72) "(#803) Some of the aliases you requested do not exist: .100000xxxxxxxxx." ["type"]=> string(14) "OAuthException" ["code"]=> int(803) } } ["message:protected"]=> string(72) "(#803) Some of the aliases you requested do not exist: .100000xxxxxxxxx." ["string:private"]=> string(0) "" ["code:protected"]=> int(0) ["file:protected"]=> string(48) "/home/www/drpetersnews.com/vmt/base_facebook.php" ["line:protected"]=> int(1106) ["trace:private"]=> array(4) { [0]=> array(6) { ["file"]=> string(48) "/home/www/drpetersnews.com/vmt/base_facebook.php" ["line"]=> int(810) ["function"]=> string(17) "throwAPIException" ["class"]=> string(12) "BaseFacebook" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> array(1) { ["error"]=> array(3) { ["message"]=> string(72) "(#803) Some of the aliases you requested do not exist: .100000xxxxxxxxx." ["type"]=> string(14) "OAuthException" ["code"]=> int(803) } } } } [1]=> array(4) { ["function"]=> string(6) "_graph" ["class"]=> string(12) "BaseFacebook" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(32) "/.100000xxxxxxxxx./feed?limit=10" } } [2]=> array(4) { ["file"]=> string(48) "/home/www/drpetersnews.com/vmt/base_facebook.php" ["line"]=> int(587) ["function"]=> string(20) "call_user_func_array" ["args"]=> array(2) { [0]=> array(2) { [0]=> &object(Facebook)#1 (7) { ["appId:protected"]=> string(15) "368XXXXXXXXXX09" ["appSecret:protected"]=> string(32) "eb4216aXXXXXXXXXXXXXXXXXXXXXfe21" ["user:protected"]=> string(15) "1000000yyyyyyyy" ["signedRequest:protected"]=> NULL ["state:protected"]=> NULL ["accessToken:protected"]=> string(119) "AAAFO5a2SKXkBAAXYgZBdPfTbJKQ3XpBgZBQmU2QcXOx7eo18hB5Hox41J7Of7SMZCj7ZCchJrM1ZCN2KLoAoqCmQWUrjwhDJlMQca005w5kgJIrMQ6ZCdM" ["fileUploadSupport:protected"]=> bool(false) } [1]=> string(6) "_graph" } [1]=> array(1) { [0]=> string(32) "/.100000xxxxxxxxx./feed?limit=10" } } } [3]=> array(6) { ["file"]=> string(40) "/home/www/drpetersnews.com/vmt/index.php" ["line"]=> int(54) ["function"]=> string(3) "api" ["class"]=> string(12) "BaseFacebook" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(32) "/.100000xxxxxxxxx./feed?limit=10" } } } }
!!!!!!!!!!!! End of Error Dump !!!!!!!!!!!!!
Please do help me out and let me know if I have set the permissions wrongly and how to do it properly.

The code is correct, but the problem could lie with Facebook's Privacy Settings. If you can't see the posts on the user's wall, it means that the user has set privacy settings preventing you from seeing the posts.
Use the Graph API Explorer tool (https://developers.facebook.com/tools/explorer/) and see if you can see the user's feed using it. Check a number of friend IDs to see if any of them return data.

Related

BTCPay Server intergration using Greenfield API / php

So I am trying to integrate btcpayserver into my site. I am fairly new to php so bare with me but I have everything working until after the invoice is created. Whenever user clicks to pay with bitcoin, it successfully creates new invoice but doesn't redirect to the checkout link afterwards.
I should mention i am using the following to help with integration process https://github.com/btcpayserver/btcpayserver-greenfield-php
Here is my create_invoice.php
session_start();
// Include autoload file.
require __DIR__ . '/../vendor/autoload.php';
// Import Invoice client class.
use BTCPayServer\Client\Invoice;
use BTCPayServer\Client\InvoiceCheckoutOptions;
use BTCPayServer\Util\PreciseNumber;
// Fill in with your BTCPay Server data.
$apiKey = 'aaaaaaaaaa';
$host = 'https://aa.demo.btcpayserver.org/';
$storeId = 'aaaaaa';
$amount = $_POST['amount'];
$currency = 'USD';
$orderId = $_SESSION['name']."#" . mt_rand(0, 1000);
$buyerEmail = $_SESSION['name'];
try {
$client = new Invoice($host, $apiKey);
var_dump(
$client->createInvoice(
$storeId,
$currency,
PreciseNumber::parseString($amount),
$orderId,
$buyerEmail
)
);
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
Whenever the form is submitted the following is shown (i replaced the sensitive information)
object(BTCPayServer\Result\Invoice)#6 (1)
{
["data":"BTCPayServer\Result\AbstractResult":private] => array(16)
{
["id"]=> string(22) "aaaaaaaaaaa"
["storeId"]=> string(44) "ssssssssssssssssssssssssssss"
["amount"]=> string(4) "18.0"
["checkoutLink"]=> string(62) "https://demo.aa.btcpayserver.org/i/aaaaaaaaaaaaaa"
["status"]=> string(3) "New"
["additionalStatus"]=> string(4) "None"
["monitoringExpiration"]=> int(1669087659)
["expirationTime"]=> int(1669080459)
["createdTime"]=> int(1669078659)
["availableStatusesForManualMarking"]=> array(2)
{
[0]=> string(7) "Settled"
[1]=> string(7) "Invalid"
}
["archived"]=> bool(false)
["type"]=> string(8) "Standard"
["currency"]=> string(3) "USD"
["metadata"]=> array(1)
{
["orderId"]=> string(4) "#501"
}
["checkout"]=> array(10) {
["speedPolicy"]=> string(9) "HighSpeed"
["paymentMethods"]=> array(1)
{
[0]=> string(3) "BTC"
}
["defaultPaymentMethod"]=> NULL
["expirationMinutes"]=> int(30)
["monitoringMinutes"]=> int(120)
["paymentTolerance"]=> float(0)
["requiresRefundEmail"]=> NULL
["defaultLanguage"]=> NULL
}
["receipt"]=> array(3)
{
["enabled"]=> NULL
["showQR"]=> NULL
["showPayments"]=> NULL
}
}
}
Now my issue is I need to redirect to "checkoutLink" after invoice is created.
UPDATE*
Following code displays error "Error: Cannot access offset of type string on string"
if ($response->getStatus() === 200) {
$data1 = $response->getBody();
$link1 = $data1["checkoutLink"];
echo $link1;
} else {
throw $this->getExceptionByStatusCode($method, $url, $response);
}

How to access XML response

Good day, I want to access the XML response and echo it to display its value but I don't know how to do it. I already tried some few answers in StackOverflow but I fail.
This is my code.
<?php
error_reporting(E_ALL);
require_once 'ruFunctions.php';
$rentalsUnited = new rentalsUnited();
$ru= $rentalsUnited->getOwners();
if($ru != null){
$data= simplexml_load_string($ru);
var_dump($data); // it will return boof(false)
var_dump($ru);
echo $data->Pull_ListAllOwners_RS->Status['ID']; //Trying to get property of non-object
}
?>
Results for var_dump($ru);
object(SimpleXMLElement)#2 (3) {
["Status"]=>
string(7) "Success"
["ResponseID"]=>
string(32) "44065d9888304e8cba912bce4d131ab1"
["Owners"]=>
object(SimpleXMLElement)#3 (1) {
["Owner"]=>
object(SimpleXMLElement)#4 (7) {
["#attributes"]=>
array(1) {
["OwnerID"]=>
string(6) "429335"
}
["FirstName"]=>
string(5) "Test"
["SurName"]=>
string(7) "Tester"
["CompanyName"]=>
string(15) "Test Helpers"
["Email"]=>
string(23) "info#Test.com"
["Phone"]=>
string(12) "+13474707707"
["UserAccountId"]=>
string(3) "602"
}
}
}
It looks like $ru is already a SimpleXMLElement, so trying to call simplexml_load_string will fail on this.
You can see some of the details by
if($ru != null){
echo $ru->Status;
}
You can (probably) list the owners by...
if($ru != null){
foreach ($ru->Owners->Owner as $owner ) {
echo "ownerId=".$owner['OwnerID'].PHP_EOL;
echo "FirstName=".$owner->FirstName.PHP_EOL;
}
}

social login php and json

I've setup Janrain social login. The only thing left is to make it more of a personalized message when logging in using this. I have no experience with php at all. It's just a practice or demo page at https://www.ntademo.com/ where you can use social login through google+ or facebook.
Here's the very top of what's returned. What'd i'd like to do is return a friendly message when someone logs in using google+ or facebook. Thank you for any input on what I should do next.
Here's a php script called rpx-token-url.php
<?php
if ($token) {
// Step 2: Use the token to make the auth_info API call.
$post_data = array(
'token' => $token,
'apiKey' => $janrain_api_key,
'format' => 'json'
);
'apiKey' => $janrain_api_key,
'format' => 'json'
);
if ($social_login_pro) {
$post_data['extended'] = 'true'; }
$curl = curl_init();
$url = 'https://rpxnow.com/api/v2/auth_info';
$result = curl_helper_post($curl, $url, $post_data);
if ($result == false) {
curl_helper_error($curl, $url, $post_data);
die();
}
curl_close($curl); if ($auth_info['stat'] == 'ok') {
echo "\n auth_info:";
echo "\n"; var_dump($auth_info);
if ($social_login_pro) {
include('social_login_pro_examples.php');
}
} else {
// Handle the auth_info error.
output('An error occurred', $auth_info);
output('result', $result);
} } else {
echo 'No authentication token.'; } $debug_out = ob_get_contents(); ob_end_clean(); ?> <head>
<title>Janrain Token URL Example</title>
</head>
<body>
<pre><?php echo $debug_out; ?></pre>
</body> </html>
auth_info:
array(4) {
["stat"]=>
string(2) "ok"
["profile"]=>
array(7) {
["providerName"]=>
string(7) "Google+"
["identifier"]=>
string(53) "https://www.google.com/profiles/xxxxxxxxxxxx"
["displayName"]=>
string(16) "My Name"
["name"]=>
array(3) {
["formatted"]=>
string(16) "My Name"
["givenName"]=>
string(4) "Mt"
["familyName"]=>
string(11) "Name"
}
["photo"]=>
string(99) "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=400"
["googleUserId"]=>
string(21) "xxxxxxxxx"
["providerSpecifier"]=>
string(10) "googleplus"
}
["merged_poco"]=>
array(5) {
["id"]=>
string(21) "xxxxxxxxxxx"
["displayName"]=>
string(16) "My Name"
["name"]=>
array(3) {
["formatted"]=>
string(16) "My Name"
["givenName"]=>
string(4) "My"
["familyName"]=>
string(11) "Name"
}
["languagesSpoken"]=>
array(1) {
[0]=>
string(2) "en"
}
["photos"]=>
array(1) {
[0]=>
array(2) {
["value"]=>
string(99) "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=400"
["type"]=>
string(5) "other"
}
}
}
["accessCredentials"]=>
array(7) {
["accessToken"]=>
string(71) "ya29.Ci-vAwW_RMSVgS9r_VCFp1JySU5dz0UoqVCgwmej3-UTUQnW8NzkLP7qDgk9N4zzxA"
["uid"]=>
string(21) "117971470422940045510"
["expires"]=>
int(1481265328)
["refreshToken"]=>
string(45) "1/JkuvkZkq060wASEY2DGUtko_AkCc_-xdyiFQFhF0PiQ"
["scopes"]=>
string(7) "profile"
["clientId"]=>
string(72) "407531817131-okq2ahfvs8ggkpmgvt6a31udmnahqemj.apps.googleusercontent.com"
["type"]=>
string(6) "oauth2"
}
}
How about replacing:
<pre><?php echo $debug_out; ?></pre>
with:
<pre><?php
if(isset($auth_info) && $auth_info['stat'] == 'ok')
echo('Hello '.$auth_info['merged_poco']['displayName'].' thanks for logging in');
else
echo('Please log in'); ?>
</pre>

simplexml_load_string() giving errors because SOAP response is being passed as < instead of <

Hey guys I'm trying to create a simple web service whereby the user enters the price in a text box then the database is queried and returns the names of dresses which corresponds to the price but I'm getting an error when I'm trying to pass the soap response in the simplexml_load_string();. This is the snapshot of the errors I'm getting:
Here's my codes for the client.php:
<?php
if(isset($_POST['search_input']))
{
try
{
$input = $_POST['search_input'];
$wsdl = "http://localhost/WebService/UDDI/90210Store.wsdl";
//$options = array('cache_wsdl'=>WSDL_CACHE_NONE, 'features'=>SOAP_SINGLE_ELEMENT_ARRAYS);
//$client = new SoapClient($wsdl, $options);
$debugOption = array('trace'=>true, 'cache_wsdl'=>WSDL_CACHE_NONE, 'features'=>SOAP_SINGLE_ELEMENT_ARRAYS);
$client = new SoapClient($wsdl, $debugOption);
$response = $client->viewDressPerPrice($input);
$soaprequest = "<strong>REQUEST:</strong><br/>" . htmlspecialchars($client->__getLastRequest()) . "<br/>";
$soapresponse = htmlspecialchars($client->__getLastResponse());
echo $soapresponse;
if(isset($response->DressPerPrice))
{
$XMLDocument = simplexml_load_string($soapresponse); //this part giving errors
$XSLDocument = new DOMDocument();
$XSLDocument->load("WSEx1.xsl");
$XSLProcessor = new XSLTProcessor();//PHP5
$XSLProcessor->importStylesheet($XSLDocument);
echo $XSLProcessor->transformToXML($XMLDocument);
}
else
{
echo "This field is not found in database";
}
}
catch(Exception $e)
{
echo 'Exception: '.$e->getMessage();
}
catch(SOAPFault $exception)
{
echo 'SOAP Exception: '.$exception->getMessage();
}
}
else
{
header("Location: http://localhost/WebService/Client/Category.html");
}
?>
var_dump($response); result:
object(stdClass)#2 (1) { ["DressPerPrice"]=> array(5) { [0]=>
object(stdClass)#3 (3) { ["Name"]=> string(7) "Dress 2" ["Price"]=>
int(20) ["Image"]=> string(24) "" } 1=> object(stdClass)#4 (3) {
["Name"]=> string(7) "Dress 9" ["Price"]=> int(20) ["Image"]=>
string(6) "3.jpeg" } [2]=> object(stdClass)#5 (3) { ["Name"]=>
string(8) "Dress 10" ["Price"]=> int(20) ["Image"]=> string(19)
"0905C58A0179_1.jpeg" } [3]=> object(stdClass)#6 (3) { ["Name"]=>
string(8) "Dress 11" ["Price"]=> int(20) ["Image"]=> string(19)
"0905C58A0179_1.jpeg" } [4]=> object(stdClass)#7 (3) { ["Name"]=>
string(8) "Dress 12" ["Price"]=> int(20) ["Image"]=> string(19)
"0905C58A0179_1.jpeg" } } }
Dress
220<img
src="2.jpeg"></img>Dress
9203.jpegDress
10200905C58A0179_1.jpegDress
11200905C58A0179_1.jpegDress
12200905C58A0179_1.jpeg
Any way that I can fix this?
Your help will be much appreciated. Thanks.

how to get only specific variable value from json response(facebook response)

I want only a specific value(say "name") from my generated output. I used this code
var_dump($request_object_details); to generate the below output.
What output I am getting:-
array(6) { ["id"]=> string(26) "514484461930096_1446926141" ["application"]=> array(2) { ["name"]=> string(18) "Pocket Financetest" ["id"]=> string(15) "270339389736782" } ["to"]=> array(2) { ["name"]=> string(12) "Prince Singh" ["id"]=> string(10) "1446926141" } ["from"]=> array(2) { ["name"]=> string(14) "Ashutosh Singh" ["id"]=> string(15) "100003645579131" } ["message"]=> string(16) "My Great Request" ["created_time"]=> string(24) "2013-01-17T03:45:36+0000" }
I used the below code to get the above output:
<?php
require_once('phps/fbsdk/src/facebook.php');
$config = array
(
'appId' => '270339389736782',
'secret' => '667e1795cc1f308f312d49d6b1c17cb8',
);
$facebook = new Facebook($config);
//get the request ids from the query parameter
$request_ids = explode(',', $_REQUEST['request_ids']);
//build the full_request_id from request_id and user_id
function build_full_request_id($request_id, $user_id) {
return $request_id . '_' . $user_id;
}
//for each request_id, build the full_request_id and delete request
foreach ($request_ids as $request_id)
{
$uid = $facebook->getUser();
$full_request_id = build_full_request_id($request_id, $uid);
$request_object_details = $facebook->api("/$full_request_id");
var_dump($request_object_details);//This is giving me the output
try {
$delete_success = $facebook->api("/$full_request_id",'DELETE');
if ($delete_success) {
echo "Successfully deleted " . $full_request_id;}
else {
echo "Delete failed".$full_request_id;}
}
catch (FacebookApiException $e) {
echo "error=".$e;}
}
?>
Your question is not clear but still I am posting some sort of code for you.
Use json_decode
Do like this : It will return object
$obj = json_decode($request_object_details);
$result= $obj->id;
OR
You can use json_decode and convert it into the array:
$request_object_details = $facebook->api("/$full_request_id");
$result=json_decode($request_object_details, true);
The second parameter will make decoded json string into an associative arrays.
Now you can directly use :
echo $result['id'];
echo $result['application'];
and so on...
Hope it'll help you.

Categories