Notification not receive - facebook

i've made a simple facebook App!
The App send notification with server: the settings are like this:
require_once __DIR__ . '/vendor/autoload.php';
$facebook = new \Facebook\Facebook([
'app_id' => 'APP_ID',
'app_secret' => 'APP_SECRET',
'default_graph_version' => 'v2.10',
]);
$facebook->post('/FB_USER_ID/notifications', array('href' => '#', 'template' => "Message to Share"), 'APP_TOKEN');
Always the message are: Success: True. but some user (example me, and other my friends) not receive a notification.. my profile allow to receive notification by that app.. and all facebook settings are right.
Why i not receive a notification and a lot of other user works fine?
Thank You

Related

Facebook API return empty set when going live

I am trying to develop a Facebook App that shows the feed of a Group inside a website.
I had my App reviewed and my permission are:
email
groups_access_member_info
default
My features are:
Group API
I use my personal Facebook account to login the App and get an Access Token.
This is the code for the login (PHP SDK)
$fb = new Facebook\Facebook([
'app_id' => 'XXXXXXXXXXX',
'app_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
'default_graph_version' => 'v5.0',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email','groups_access_member_info'];
$loginUrl = $helper->getLoginUrl('https://mywebsite.com/fb-callback.php', $permissions);
I have 2 problems:
After around 15 calls I got an error saying that I reached the limit and I need to wait an hour.
If I put the App in Live mode I got an empty set as result.
Below the code for the call:
$fb = new Facebook\Facebook([
'app_id' => 'XXXXXXXXXXX',
'app_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
'default_graph_version' => 'v5.0',
]);
$fields = array('id', 'name', 'full_picture', 'message', 'permalink_url', 'type',
'created_time', 'description', 'is_published', 'attachments{media}');
$response = $fb->get('/[GROUP_ID]/feed?fields='.implode(',',$fields), FACEBOOK_TOKEN);
$fb_decodedbody = $response->getDecodedBody();

How to fix Facebook App Login Error

I am new to Facebook App Developing. I am trying to use facebook login. But this error is popping up. 1 This is my code.
<?php
session_start();
require_once 'Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => '240676292969845', // Replace {app-id} with your app id
'app_secret' => '111111111111111111111',
'default_graph_version' => 'v2.2',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email']; // Optional permissions
$loginUrl = $helper->getLoginUrl('https://warunaphotography.com/fb-callback.php', $permissions);
echo 'Log in with Facebook!';
?>
This is the facebook app settings.
3
Please help me.

Trying to post to facebook page with app but get "The user hasn't authorized the application to perform this action"

I am trying to write a script that will post an update to a facebook page timeline. I created an app and created a key for the app. I am using the code below:
require_once HOME_PATH . '/include/facebook/facebook.php';
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_APP_SECRET,
'cookie' => true,
'scope' => 'publish_stream',
));
$user_id = $facebook->getUser();
$access_token = $facebook->getAccessToken();
$attachment = array(
'access_token' => $access_token,
'message' => 'this is my message',
'name' => 'name',
'link' => ROOT_URL . $blog_data['url'] . '.htm',
'caption' => $blog_data['title'],
'description' => $blog_data['title'],
);
if ($image = get_first_image($blog_data['body'])) {
$attachment['picture'] = $image;
}
$facebook->api(FACEBOOK_BLOG_PAGE . '/feed', 'post', $attachment);
i think this key is connected to the app and not to my user, so it sounds like i would have to grant the permission within facebook, but i have seen some other posts telling me that i need to do this in code. The examples aren't very clear.
I know similar questions have been asked but i haven't seen any clear answers yet. Can anyone please clarify this?
If you want to get user_id by this piece of code: $user_id = $facebook->getUser();
The first thing you need, is to login an user through a URL returned by $facebook->getLoginUrl(array('scope' => array('perm', 'perm2'))).
Also, notice, where I put permissions, which I require. Not into the Facebook class constructor, but into the method getLoginUrl.
And lastly, for posting into a page, you need publish_actions permission (not publish_stream).

PHP SDK: Post to FB application's wall as the app itself

There are a lot of questions on SO about this, but not exactly what I am looking for.
In my case, users can log in through Facebook/Twitter/other. And they can upload an image.
Once they upload an image, two things will happen. The FB user's status is updated with an attachment to the link. And on the FB App's wall, a status update is also posted but by the application itself and not by the user. I am having trouble with this last part. So the user does not have to be logged in through Facebook for this latter to occur.
My code:
$facebook = new Facebook($config);
$attachment = array(
'message' => 'A user just posted a new item',
'name' => $tag,
'caption' => $desc,
'link' => WEBURL,
'description' => '',
'picture' => $img,
'actions' => array(array('name' => 'Go to item',
'link' => WEBURL))
);
$facebook->api('/'.PAGEID.'/feed', 'POST', $attachment);
An application's wall behaves exactly like a page's wall or a user's wall. Lookup the documentation for those.

Send notification or post on wall

i have been going crazy and cant figure out how to make a script for my application that would allow the user to select a friend and send them a notification or post on their wall from my application.
I just need to notify their friend that they have been challenged to play a flash games, just a simple text with a link, i dont need anything fancy :D
Here is what i tried and it doesnt work :( no idea why.
$message = 'Watch this video!';
$attachment = array( 'name' => 'ninja cat', 'href' => 'http://www.youtube.com/watch?v=muLIPWjks_M', 'caption' => '{*actor*} uploaded a video to www.youtube.com', 'description' => 'a sneaky cat', 'properties' => array('category' => array( 'text' => 'pets', 'href' => 'http://www.youtube.com/browse?s=mp&t=t&c=15'), 'ratings' => '5 stars'), 'media' => array(array('type' => 'flash', 'swfsrc' => 'http://www.youtube.com/v/fzzjgBAaWZw&hl=en&fs=1', 'imgsrc' => 'http://img.youtube.com/vi/muLIPWjks_M/default.jpg?h=100&w=200&sigh=__wsYqEz4uZUOvBIb8g-wljxpfc3Q=', 'width' => '100', 'height' => '80', 'expanded_width' => '160', 'expanded_height' => '120')));
$action_links = array( array('text' => 'Upload a video', 'href' => 'http://www.youtube.com/my_videos_upload'));
$target_id = $user;
$facebook->api_client->stream_publish($message, $attachment, $action_links, $target_id);
UPDATE:
appinclude.php
$facebook->redirect('https://graph.facebook.com/oauth/authorize?client_id=132611566776827&redirect_uri=https://apps.facebook.com/gamesorbiter/&scope=publish_stream');
Error i get:
{
"error": {
"type": "OAuthException",
"message": "Invalid redirect_uri: The Facebook Connect cross-domain receiver URL (https://apps.facebook.com/gamesorbiter/) must be in the same domain or be in a subdomain of an application's base domain (gamesorbiter.com). You can configure the base domain in the application's settings."
}
}
Without the extra "s"(http) i get this error:
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
Please if you could post an example.
Also do i need extended permission to do that or if the user sends the message i dont need that ?
Thank You
Also do i need extended permission to
do that or if the user sends the
message i dont that ?
Yes, you need the offline_access and publish_stream extended permission from the users.
Update:
In your appinclude.php file, put code like this:
$facebook = new Facebook($appapikey, $appsecret);
$user = $facebook->require_login();
$facebook->redirect('https://graph.facebook.com/oauth/authorize?
client_id=[YOUR APP ID]&
redirect_uri=[YOUR APP URL]&
scope=publish_stream, offline_access');
Replace [YOUR APP ID] with application id that you can see from application settings where you created the site in Facebook Developers section. Also replace the [YOUR APP URL] with your app url.