I'm using the Graph API code that uses an acces_token and an id_page with permissions to post to a fan page. It works as long as the user is logged, but when I log out the access_token expires and I can't publish to fan page.
How can I make my application to be able to publish at any time, even when the user is not logged in?
This is my code:
<?php
$page_access_token = 'AAAFNxxxx';
$page_id = '15203xxx';
$data['picture'] = "https://www.google.it/logos/2012/moby_dick12-hp.jpg";
$data['link'] = "http://www.google.it/";
$data['message'] = "Test";
$data['description'] = "Lorem ipsum dolor sit amet";
$data['access_token'] = $page_access_token;
//curl connection
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch); ?>
You can use extended token to post when the user has logged out, by retrieving the same exchanging you own client_id (your app_id), your app_secret, and the non-expired, short-lived access_token
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
Make pending posts in your word press blog, connect your blog with networkbloggers and fanpage.So it will be: Your awaesome WP + Networkbloggers = post on Facebook Fanpage
That must work i'm using it long time every time my post enter on my facebook fan page no need app. or something more complicate
Related
I have everything set up and everything was working properly. I have a popup where the user can reply to a review on their business page. This was also working fine.
My code looks like this:
$url = "https://graph.facebook.com/v3.2/221454575852164769/comments";
$attachment = array(
"access_token" => $page_access_token,
"message" => "Thank you so much!!",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($attachment));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$comment = curl_exec($ch);
curl_close ($ch);
$comment = json_decode($comment, TRUE);
This was working fine. Even now this script is working but the issue is it returns this error
Unsupported post request. Object with ID '221454575852164769' does not exist, cannot be loaded due to missing permissions, or does not support this operation
Even after the Curl receives error when I go and check into the reviews on Facebook the comment was successfully posted.
Any help?
From the duplicate I flagged, you'll see you may need to submit your app for App Review to Facebook for permissions.
https://developers.facebook.com/docs/facebook-login/permissions/v3.0
How do I test a Facebook app since the recent introduction of login review?
Either that or you mis-typed a paramater/variable, hence the incorrect 18-digit ID number since it can't reference that instance of an object.
How to post a notification to users as application using facebook php sdk?
I have attached an image, in that picture we can see application from SongPop post a notification to me. I want to make something like this. I think this app post notification to their users, can I post a notification to a spesific user?
you have to a canvas page url set to in your app config then try with this code
$url = "https://graph.facebook.com/$user_id/notifications";
$notification_message = 'My Example Notification Message';
$app_access_token = $app_id . '|' . $app_secret;
$attachment = array(
'access_token' => $app_access_token, // access_token is a combination of the AppID & AppSecret combined
'href' => '', // Link within your Facebook App to be displayed when a user click on the notification
'template' => $notification_message, // Message to be displayed within the notification
);
// set the target url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch);
1) I got my facebook app setup.
2) I got my facebook page id, app_secret and access token.
function fetchUrl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$feedData = curl_exec($ch);
curl_close($ch);
return $feedData;
}
$profile_id = "288644066152";
//App Info, needed for Auth
$app_id = "appid";
$app_secret = "app_secret"; // do not expose app secret!
//Retrieve auth token
$authToken = fetchUrl("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={$app_id}&client_secret={$app_secret}");
$json_object = fetchUrl("https://graph.facebook.com/{$profile_id}/feed?{$authToken}");
print_r($json_object);
RETURNS:
{"data":[]}
Any help out there?
Thanks
There are 2 types of access tokens. The user access token, & the app access token.
Try something like:
https://www.facebook.com/dialog/oauth?client_id=******&redirect_uri=*************&scope=user_about_me,publish_stream,friends_about_me,****&state=SOMETHING
I create a simple form. When I put data in all fields of the form and press a submit button, then all data that were completed on the form should be sent to a Web service client (rest).
My question is, how to send all data from my form to web service? Is there a module for that or I have to draw on an API?
Thanks :D
UPDATE:
I created my form that contains 2 fields: "Name" and "Phone" and a submit button. (All in my own module)
Then I show my code that I just did. However, when I see the web service. The shipping data, not shown. I did a debug and uh I realized that when running: "curl_exec ($ch)" returns me FALSE.
function mymodule_form_submit($form, &$form_state){
$name = $form_state['values']['name'];
$phone = $form_state['values']['phone'];
$data = array(
'name' => $name,
'phone' => $phone
);
$url = 'http://[IP]/event/management/attendee';
$headers = array('Content-Type: multipart/form-data');
$userpasswd = 'user:pass';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_USERPWD, $userpasswd);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$result = curl_exec($ch);
curl_close($ch);
}
The params,in the web service, are: attendee['name'], attendee['phone']. What is my error?
Sure man try the service module 3 . It's one of drupal great module as usual .
here's the link ( http://drupal.org/node/736522 ) , you can also authenticate user before getting the fields by using two techniques either session authentication or aouth authentication .. you can call your drupal from client application by one of those approach "json,xml-rpc, rest".
1- first the session authentication takes a user name and password and authenticates. Then it takes the user permissions from drupal so you need to authenticate in each step to go through your application that communicate with your drupal. Anonymous users can get what they want according to your permission in drupal.
2- While in Aouth authentication you create a user and add token to him and only the user who had the token communicate with the application according to the permission rule you set to him . In case of anonymous users they can't retrieve or get anything. The communication between drupal and the client within the created used with a certain token.
Feel free to contact me for more support.
sorry for miss-understanding .
there's two implementation method to do this :
1- You may do a custom module which hooks on the node_api and on submit form get posted data and send it to webservice by this method
$json = drupal_http_request('http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false');
$decode = json_decode($json->data, TRUE);
or by using this module web service client module ( http://drupal.org/project/wsclient ) this is only for drupal 7
2- and this is a guide about this module http://drupal.org/node/1114308 .
I have a web service that works fine with get requests but trying to use post it doesn't seem to work. I have this in my routes:
Router::connect("/products/service_add", array("controller"=>"products", "action" => "service_add", 'seller'=>true, "[method]" => "POST"));
Seller is like an admin. I also have ParseExtensions('xml'). My action is:
function seller_service_add() {
$this->log("hit", 'debug');
$hi = array("message"=>"hey");
$this->set(compact('hi'));
}
and the view is:
<product>
<?php echo $xml->serialize($hi); ?>
</product>
When I try to send a post to the API I just get a debug trace back with timer info. In the same script as I'm doing the post request I'm doing a get and when I run the script I can see the data passed by the API for the get but not for the post request.
The code I'm using to send the post is:
$ch = curl_init();
$data = array('Your' => 'Data');
curl_setopt($ch, CURLOPT_URL, "http://localhost/<project>/products/service_add.xml");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);`
Any ideas on why this isn't working? Any help would be much appreciated.
Sorry if this is a bit verbose!
Update: I've added lines to spit stuff out to the cakephp debug log when actions are hit. I have one entry on the beforeFilter, this entry gets hit and I can see it in the log. The entry in the service_add action is not present in the log so I guess that the action is not being hit?
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
shouldn't this line be
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);