Is Facebook batch request photo upload with no_story possible? - facebook

Is it?
Uploading works like a charm, but I don't want it to show up on timeline or feed.
I've tried adding no_story to each request, and to the $params which is commented out in following code:
foreach ($data['Ad']['Media'] as $medium) {
$file = $medium['tmp_name'];
$req = array(
'method' => 'POST',
'relative_url' => '/me/photos',
'message' => $data['Ad']['title'],
'attached_files' => 'file' . $count,
'no_story' => 1 //Also tried 'true'
);
//add this request to batch
$batch[] = json_encode($req);
$params['file' . $count] = '#' . realpath($file);
$count++;
}//foreach
$params['batch'] = '[' . implode(',', $batch) . ']';
//$params['no_story'] = true;
Edit ##
See comment below.

i know you may not need the answer any more, but i was facing same issue , and after a lot of try and error i figured it out so i will post the answer may be some one face this issue again
$req = array(
'method' => 'POST',
'relative_url' => '/me/photos',
'attached_files' => 'file' . $count,
'body' => 'no_story=1'
);

Related

Facebook SDK 5.3 returning empty 'data' array in the body

Using the following code:
$postId = "<userid>_<post_id>";
$this->facebook = new Facebook([
'app_id' => $container->getParameter('facebook_client_id'),
'app_secret' => $container->getParameter('facebook_client_secret'),
'default_graph_version' => 'v2.5',
]);
$app = $this->facebook->getApp();
$request = new FacebookRequest(
$app,
'<access_token>',
'GET',
'/' . $postId . '/sharedposts?fields=from,via'
);
$response = $this->facebook->getClient()->sendRequest($request);
print_R($response); exit();
returns the following:
[body:protected] => {"data":[]}
[decodedBody:protected] => Array
(
[data] => Array
(
)
)
But I can clearly see, within Facebook, that there is a comment, a share and a like on the post Id i'm querying
My end goal is to view how many times a post to FB has been shared by other FB users

Drupal7 REST: I am not able to perform POST and PUT methods. Error is :Not Acceptable : Node type is required, Code:406?

I'm using drupal7. my drupal_http_request() for get and delete are working fine for authenticated users, but the post and put methods are not working.
The error is :Not Acceptable : Node type is required, and http error code is :406. My code is below:
function ws_form_post_auth() {
$base_url = 'http://localhost/drupalws/api/v1';
$data = array(
'username' => 'student1',
'password' => 'welcome',
);
$data = http_build_query($data, '', '&');
$options = array(
'headers' => array(
'Accept' => 'application/json',
),
'method' => 'POST',
'data' => $data
);
$response = drupal_http_request($base_url . '/user/login', $options);
$data = json_decode($response->data);
// Check if login was successful
if ($response->code == 200) {
$options['headers']['Cookie'] = $data->session_name . '=' . $data->sessid;
$options['headers']['X-CSRF-Token'] = $data->token;
$data = array(
'title' => 'First forum post',
'type'=> 'forum',
'body'=> array(
'und'=>array(
0=> array(
'value'=>'This is my first forum post via httprequest.'
)
)
)
);
$data = json_encode($data);
$options['data'] = $data;
$options['method'] = 'POST';
$response = drupal_http_request($base_url . '/node', $options);
return $response->status_message;
}
return $response->status_message;
}
I got the solution for my issue,I just missed a Content-Type in Headers.
[....]
if ($response->code == 200) {
$options['headers']['Cookie'] = $data->session_name . '=' . $data->sessid;
$options['headers']['X-CSRF-Token'] = $data->token;
$options['headers']['Content-Type'] = 'application/json';
[....]

Facebook PHP SDK - An active access token must be used to query information about the current user

I have problem with Facebook PHP SDK. It always throws that exception. I tried many solutions listed here, but nothing works for me.
It seems that Facebook returns to me valid access token, because I tested it with Debug tool in dashboard of my application.
What's my scenario?
I want to post to publish simple content to user's wall by calling static function:
function social_publish($network, $title, $message, $link = '', $image = '') {
global $_config;
// Initialize Facebook SDK
$facebook = new Facebook(array(
'appId' => $_config['fb_app']['app_id'],
'secret' => $_config['fb_app']['app_security_key']
));
// Set data
$attachment = array(
'name' => $title,
'caption' => $title,
'message' => $message,
'link' => $link,
'picture' => $image,
'actions' => array('name' => 'Test', 'link' => 'Link')
);
try {
$access_token = $facebook->getAccessToken(); // returns valid access token
$uid = $facebook->getUser(); // always return 0
$result = $facebook->api( '/' . $_config['fb_profile'] . '/feed/', 'post', $attachment); // $_config['fb_profile'] procudes 'me' in this case
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
}
Just to note: I am not working on local environment.
problem solve it as asked in scope request to Facebook for authentication, as I decided to use the JavaScript SDK-and then, here's the solution:
FB.getLoginStatus(function(response) {
if ( ! response.authResponse ) {
FB.login(function(response) {
// handle the response if needed
}, {scope: 'publish_actions, publish_stream'});
}
});
Thank you! :-)

Tagline does not appear on the Iphone for facebook application when post to user wall?

I have a facebook application that can post (message,link,image) to user wall
The tagline(via status appname) does not appeared when I see the userwall or homepage
This is the code:
// in case of image
$image = "image url"
$attachment = array(
'message' => $message,
'source' => $image,
'url' => $image
);
$photo = true;
// in case of youtube link
$attachment = array(
'message' => $message,
'link' => 'http://www.youtube.com/watch?v=' . $video_id,
'source' => 'http://www.youtube.com/v/' . $video_id,
'description' => $description,
'picture' => 'http://img.youtube.com/vi/' . $video_id . '/0.jpg',
);
//incase of text
$attachment = array(
'message' => $message,
'name' => $title,
);
}
foreach($users as $uid=>$token){
$attachment['access_token'] = $token;
if (isset($photo)) {
$facebook->setFileUploadSupport(true);
$fb_result = $facebook->api('/' . $uid . '/photos', 'post', $attachment);
} else {
$fb_result = $facebook->api('/' . $uid . '/feed/', 'post', $attachment);
}
}

Creating an event-invite using the old REST API

I cannot do the following with the Graph API, so I'm trying to do it with the old REST API,
but without any success... No error message, but also no invite.
$restApi = $facebook->api(array(
'method' => 'events.invite',
'eid' => $eid,
'uids' => $testuserId,
'personal_message' => 'testing',
'access_token' => $accesstoken,
));
print '<pre>' . print_r($restApi, true) . '</pre>';
Or maybe some of you know a better way...
There is a open Vote on Event Invites with Graph API at the FB Bugzilla http://bugs.developers.facebook.net/show_bug.cgi?id=10070
And I think your problem is that you need an array of uids try:
$restApi = $facebook->api(array(
'method' => 'events.invite',
'eid' => $eid,
'uids' => array($testuserId),
'personal_message' => 'testing',
'access_token' => $accesstoken,
));
print '<pre>' . print_r($restApi, true) . '</pre>';
-michael