Looping through Facebook\GraphObject Object in php - how is it done? - facebook-graph-api

I've tried a bunch of different ways from Google and Stack, and https://developers.facebook.com/docs/php/GraphObject/4.0.0?locale=en_GB, but I can't successfully loop through this object. I want to test if the email permission is granted or declined. How is looping done with this? Thanks for your guidance.
Facebook\GraphObject Object
(
[backingData:protected] => Array
(
[0] => stdClass Object
(
[permission] => public_profile
[status] => granted
)
[1] => stdClass Object
(
[permission] => email
[status] => declined
)
)
)

Use the asArray() method of GraphObject
foreach($graphObject->asArray() as $data) {
// data is a stdClass
$status = $data->status;
}

Related

How to add people to facebook ad account in business manager

I am trying to create ad account by following https://developers.facebook.com/docs/marketing-api/reference/ad-account. With the help of this code I could successfully create ad account but I want to add myself as people as well but not getting any way to do this.
My ad account creation parameters are like
$attachment = array(
'access_token' => $this->accessToken,
'name' => $associative_arr['name'],
'currency' => $associative_arr['currency'],
'timezone_id' => $associative_arr['timezone_id'],
'end_advertiser' => $this->businessAccount,
'media_agency' => 'NONE',
'partner' => 'NONE',
'user_role' => '1001'
);
and endpoint is
https://graph.facebook.com/v2.8/BUSINESS_ID/adaccount
I also tried updating ad account using following
https://developers.facebook.com/docs/marketing-api/aduser/v2.8
but no gain.
I am getting following error.
stdClass Object
(
[error] => stdClass Object
(
[message] => (#10) Application does not have permission for this action
[type] => OAuthException
[code] => 10
[fbtrace_id] => HyAJtY0OOMf
)
)
Can anyone give me suggestions how I can ad people to my ad account using curl or PHP SDK?
Besides getting the ads_management permission, what was your app's Marketing API access level? The default access level supports up to only 5 ad account access. If you've accessed more than that via the API, you won't be able to do that on more accounts unless you apply for higher level of access. You can manage your ad account list in your app dashboard.

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.

Facebook C# SDK Upload Photos with Tagging data Graph API

How do i upload a photo with tagging info using graph api ?
the php solution i found is at http://forum.developers.facebook.net/viewtopic.php?id=86152
$data = array(
'tag_uid' => $friend,
'x' => rand() % 100,
'y' => rand() % 100
);
$datatags[] = $data;
$attachment = array(
'access_token' => $access_token,
'tags' => $datatags
);
$facebook->setFileUploadSupport(true);
$attachment['image'] ='#'.realpath($filename);
$photo = $facebook->api('/'.$aid.'/photos', 'POST', $attachment);
just need to know the syntax to add multiple tags.
thanks.
You can set multiple tags by passing array of tag arrays like in this example: Uploading image and tagging multiple people in one step using PHP Facebook Graph API