Facebook API, make a draft or privacy "self" - facebook-graph-api

i use Facebook API to publish on my Facebook page. My code works, but now i need to publish my post or like draft or with privacy "self", but it's still publishing post visible to everyone. Here's my code:
public function makeOggistiPost($queryRow)
{
$pageId = PAGE_ID;
$pageToken = $this->dbService->getPageToken($pageId);
if (!empty($pageToken)) {
$postMessage = [
$this->clearString($queryRow->titolo_ita),
$this->clearString($queryRow->abstr_ita),
"Continua su https://www.progettohmr.it/OggiSTI/?id=" . $queryRow->id_evento
];
try {
$response = $this->facebook->post("/" . $pageId . "/photos", [
"message" => implode(" ", $postMessage),
"url" => HMR_URL . $queryRow->immagine,
"privacy"=> '{value: "SELF"}',
"published" => "true"
], $pageToken);
Someone could tell me how to make my post like a draft or with privacy "self"? Thank you.

Those privacy settings are for user profiles. Try setting is_published to false instead.
https://developers.facebook.com/docs/graph-api/reference/v3.1/post

Related

Not redirecting to payment page when payment created

I am trying to integrate laravel-mollie in my website using in the example that they are providing the example. When i'm creating new payment it should redirect me to payment page, But its not showing anything.. here is my code:
public function preparePayment($data, $orderId)
{
$payment = Mollie::api()->payments()->create([
'amount' => [
'currency' => 'EUR',
'value' => '100.00', // You must send the correct number of decimals, thus we enforce the use of strings
],
"description" => "My first API payment",
"redirectUrl" => route('mollie.payment.status'),
'webhookUrl' => route('webhooks.mollie'),
"metadata" => [
"order_id" => $orderId,
],
]);
$payment = Mollie::api()->payments()->get($payment->id);
// redirect customer to Mollie checkout page
return redirect($payment->getCheckoutUrl(), 303);
}
I printed the url. which is showing the link. But not redirecting to the payment page. What did i do wrong! can anyone point me out?
The $payment object looks ok, just double check if your param for the redirectUrl is correct.
Also if I'm not mistaken the redirect to an external URL in Laravel should be something like:
...
return redirect()->away($payment->getCheckoutUrl());

Facebook Graph API get page_impressions

I've been using the graph api to get insights for our page. I log in, authorise and get a page access token. Recently, Facebook made it impossible to get any data without getting your app reviewed. I've managed to get my app reviewed with the following permissions:
manage_pages, email, read_insights, default:
These are found here: https://developers.facebook.com/docs/facebook-login/permissions/
This is my call:
https://graph.facebook.com/v3.0/me/insights/page_impressions_by_age_gender_unique
And this is the response:
{
"data": [
],
"paging": {
"previous":
"https://graph.facebook.com/v3.0/300196376675661/insights?access_token=xxx&pretty=0&metric=page_impressions_by_age_gender_unique&since=1532674800&until=1532847600",
"next": "https://graph.facebook.com/v3.0/300196376675661/insights?access_token=xxx&pretty=0&metric=page_impressions_by_age_gender_unique&since=1533020400&until=1533193200"
}
}
Are there additional permissions that I need to get in my app? Has anyone managed to get these insights?
Looking for these items:
[
("page_impressions_by_age_gender_unique", "day"),
("page_impressions", "day"), ("page_impressions_unique", "day"),
("page_impressions_paid", "day"),
("page_views_by_age_gender_logged_in_unique", "day")
]
This might help!
Your query should be like this =>
"<your_page_id>/insights?metric=page_impressions_by_age_gender_unique&accessToken=<your_page_access_token>"
Make sure to pass the Page Access Token, not user token.

signedRequest not working for liked field anymore

While developing facebook apps I want to fetch the liked status of a page to redirect them accordingly.Earlier I used the following code:
<?php
require 'facebook.php';
$app_id = "**************";
$app_secret = "*************************************";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
if($like_status==1)
echo "liked";
else
echo "not liked";
?>
But due to the new policy by facebook, in the apps developed after 7th aug 2014 I cannot get the page liked status using this method.
Pages.isFan() is also not working and FQL I read will not last long. Is there any other method to do it?
https://developers.facebook.com/docs/apps/changelog
Fangates are dead, they donĀ“t work for new Apps anymore, and there is no other way to do it. They also forbid them in the Platform Policy (see Changelog):
You must not incentivize people to use social plugins or to like a
Page.
That is why the like value in signed_request was removed.

Facebook API - App using Oauth to update status of page

I have built an app using the PHP Facebook SDK. It allows users to authenticate my app with facebook OAth so that they can update their status' via my App. This works great, however a lot of my users have business pages and they want to update the status on their business page not their main personal feed. How is this possible? Below is what I have so far.
if ($status != ''){
try {
$parameters = array(
'message' => "$status"/*,
'picture' => $_POST['picture'],
'link' => $_POST['link'],
'name' => $_POST['name'],
'caption' => $_POST['caption'],
'description' => $_POST['description']*/
);
//add the access token to it
$parameters['access_token'] = $access_token;
//build and call our Graph API request
$newpost = $facebook->api(
'/me/feed',
'POST',
$parameters
);
$success['status'] = "$xml->status";
$xml2 = new XMLGenerator($success, 'facebook','status');
$returnData = $xml2->output;
$returnData = APIResponse::successResponse('200', "$xml->status");
} catch (Exception $e) {
$returnData = APIResponse::errorResponse('400', 'Facebook Error: '.$e);
}
I assume I would have to change '/me/feed'? but to what? What is they have multiple pages how would my app know which page to post to?
Any help with this would be much appreciated.
You can substitute me with the PAGE_ID to post to a page e.g., /013857894/feed. Make sure that you have completed the OAuth process with the manage_pages and publish_stream permissions. You can learn more at the link below:
https://developers.facebook.com/docs/reference/api/page/#statuses
If the user has multiple Pages then you will first need to give them some way of selecting which page they want to post to. You can find out which Facebook Pages a given user is the administrator of by calling /me/accounts for that user. You can find out more about this approach in the Connections section of this page:
https://developers.facebook.com/docs/reference/api/user/

How to use CUSTOM privacy setting for facebook post from an app in php

In PHP with facebook SDK, when I post from my app using /me/feed, if I use 'SELF' for privacy setting, it works fine. When I change it to CUSTOM with a list of ids to restrict to, I get an error for "friends" was not recognized. What does this mean?
// Works
$privacy = array(
'value' => 'SELF',
);
// Doesn't work and says 'Friends was not recognized'
$privacy = array(
'value' => 'CUSTOM',
'allow' => '{<id1>}'
}
I read through many questions on this topic before asking this one.
Also, this documentation from FB is confusing me as to what is and is not possible for an post from an app.
"Note: The privacy parameter only applies for posts to the user's own timeline and is ultimately governed by the privacy ceiling a user has configured for an app. It does not apply to posts made by an app on behalf of a user to another user's timelines or to Pages, events, or groups. In those cases, such posts are viewable by anyone who can see the timeline or content in the group or event."
you need to add a parameter called 'friends' with the value of 'SOME_FRIENDS'.
like this:
$privacy = array(
'value' => 'CUSTOM',
'friends' => 'SOME_FRIENDS',
'allow' => 'id1,id2,id3'
);