i have a#yahoo.com account and also created facebook account
another two users have also facebook account by b#yahoo.com and c#yahoo.com per each.
b#yahoo.com and c#yahoo.com account holder pressed like button of the fan page owned by
a#yahoo.com holder.
now as a fan page [a#yahoo.com] but not as others, I like to post some
message,attachment [to the wall of
the selected users + users who liked fan page] among all of the users.
now I select only b#yahoo.com user.
the code is given below:
I accepted manage_pages,offline_access,publish_stream permission.
$page_id = "YYYYYYYYYYYYYYYY";
$page_access_token = "";
$result = $facebook->api("/me/accounts");
foreach($result["data"] as $page) {
if($page["id"] == $page_id) {
$page_access_token = $page["access_token"];
break;
}
}
$data["access_token"] = $page_access_token;
$data["message"] = "aaaaaaaaaaaaaaaaa";
$data["name"] = "ttttttttttttt";
$data["caption"] = "cccccccccccccc";
$data["link"] = "http://www.facebook.com/pages/CCCCC/OOOOOsk=app_UUUUUUUUUUU";
$data["description"] = "aaaaaaaasdfsfsdf";
$data["picture"] = "http://cdn1.kingdomsofcamelot.com/fb/e2/src/img/fte/army_troop.png";
$post_id = $facebook->api("/$page_id/feed", "post", $data);
but the above code post the message,attachment to the wall of all users who liked
the fan page,but I only write post to the specific users.
how can I achieve? or is there any possiblity to pass the target users id only?
I'm not entirely sure i understood your problem.
Your code posts a post to the fan-page wall - not to the "wall of all users who liked the fan page".
As a fan page, you can not write to a user's wall, even if he is a fan of your fan-page.
Related
I have registered an app in facebook developers program and I can retrieve posts from facebook page using fb api, but I cannot retrieve posts from facebook profile. Should I use some different access token for both page or profile? Is there a different way for retrieving posts from facebook page and profile?
Any help will be appreciated!
You may need the user_status permission.
And you call the posts using this graph query {USER_ID}?fields=statuses
Prerequisite:- You need to have valida FB token for all the request:-
I am answering using c# language.
Step 1:- First you need to get the user's FB id using FB token
I am using Facebook SDK 7.0.6 for querying purpose
here's how to initialize the FB service which we will use in our consecutive calls.
FacebookService facebookService = new FacebookService(facebookToken);
var _facebookClient = new Facebook.FacebookClient(token);
Code snippet
public string GetFacebookID(string facebookToken)
{
dynamic result = _facebookClient.Get("me?fields=id");
if (result.ToString().Contains("id"))
{
return result["id"];
}
return string.Empty;
}
after that you can execute below method to get user's post using FB ID and token
public List<Post> GetPostsForUser(string facebookID)
{
List<Post> posts = new List<Post>();
dynamic result = _facebookClient.Get(facebookID + "/posts"); //Case Sensitive, Posts doesn´t work
if (result.ToString().Contains("data") && result.data.Count > 0)
{
foreach (var item in result.data)
{
posts.Add(new Post
{
ID = item.id,
Story = item.story,
Message = item.message,
Created_Time = Convert.ToDateTime(item.created_time),
Reactions = GetReactions(item.id)
});
}
result = _facebookClient.Get(GetNextURL(result.ToString()));
}
return posts;
}
So I tried to post on my friends wall using the following code:
var fb = new FacebookClient(_accessToken);
dynamic parameters = new ExpandoObject();
parameters.message = "Google is your friend";
parameters.link = "http://gidf.de/";
parameters.Name = "Test";
parameters.from = new { id = "100000", name = "me" };
parameters.to = new { id = "1000001", name = "friend" };
dynamic result = fb.Post("1000001/feed", parameters);
However, I get told that my application does not support this. I did some googling work, and read that [USER_ID]/feed is deprecated and that I have to invoke the feed dialog to ask the user to publish it. How would I go on doing this with the C# SDK?
As of February 6, 2013, you can't post to Friends Timeline on behalf of the user.
Read Here: https://developers.facebook.com/roadmap/completed-changes/
Client-Side you can use the FB.ui method to pop up the feed dialog.
Here's an example: https://stackoverflow.com/a/15426243/1405120
Server-Side, you can use the URL Redirection.
https://www.facebook.com/dialog/feed?
app_id=458358780877780
&link=https://developers.facebook.com/docs/reference/dialogs/
&redirect_uri=https://mighty-lowlands-6381.herokuapp.com/
Read more about Feed dialog here, https://developers.facebook.com/docs/reference/dialogs/feed/
I have my android application allowing user to share interesting fragments of some texts on the Facebook.
Sharing on the user's wall works fine and is implemented using this tutorial:
http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
I also have a facebook fan page of my application and I would like to consolidate all such individual shares on that page.
So that when some user shares text on their wall the program would also publish this on facebook fan page, so that if someone is interested in the discussion they could like the fan page and subscribe to all the comments other users make.
My problem is that I can either publish on user's wall or publish on fan page.
How can I do both at the same time?
public void postToWall(){
Bundle parameters = new Bundle();
parameters.putString("message", this.messageToPost);
parameters.putString("description", this.messageDesc);
parameters.putString("link", this.messageLink);
// parameters.putString("target_id", FAN_PAGE_ID);
try {
facebook.request("me");
// String response = facebook.request("me/feed", parameters, "POST");
String response = facebook.request(FAN_PAGE_ID+"/feed", parameters, "POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
showToast("Blank response.");
}
else {
showToast("Message posted to your facebook wall!");
}
finish();
} catch (Exception e) {
showToast("Failed to post to wall!");
e.printStackTrace();
finish();
}
}
This line publishes to user's wall
String response = facebook.request("me/feed", parameters, "POST");
And this one to fans page
String response = facebook.request(FAN_PAGE_ID+"/feed", parameters, "POST");
I have set up permissions for my app to publish on the fan page using this post
Simple example to post to a Facebook fan page via PHP?
I had the same issue and I just did the requests via two asyncfacebookrunner classes. So basically they are happening in parallel.
private AsyncFacebookRunner mAsyncFbRunner;
private AsyncFacebookRunner mAsyncFbRunner2;
public void postToWall() {
boolean success = true;
Bundle params = new Bundle();
//this is for posting on the walls
parameters.putString("message", this.messageToPost);
parameters.putString("description", this.messageDesc);
parameters.putString("link", this.messageLink);
mAsyncFbRunner.request("me/feed", params,"POST", new WallPostListener(), success);
mAsyncFbRunner2.request(FAN_PAGE_ID+/"feed", params,"POST", new WallPostListener(), success);
}
I am working with the Graph API but I have found it to be rather limited. In the news feed on the Facebook website you might see "X and 14 other friends likes Y page." or "X and 3 other friends has changed their profile picture."
In the Graph API it will look like the code below when X and 14 other friends has liked the same page. The Graph API only returns the name of X but not how many friends other than X who have liked the page.
{
application = {
id = 01010101;
name = Pages;
};
comments = {
count = 0;
};
"created_time" = "2011-08-15T08:35:47+0000";
description = "Description of page.";
from = {
id = 1111;
name = "X";
};
icon = "---";
id = "http://static.ak.fbcdn.net/rsrc.php/v1/yN/r/xC785tTCIQO.gif";
link = "http://..../";
name = "Y";
picture = "---";
type = link;
"updated_time" = "2011-08-15T08:35:47+0000";
}
I don't see any way to get this information. Am I right or am I missing something?
It depends on the type of object you are accessing. Recently, Facebook have begun to hide useful info such as who specifically liked something, I'd imagine because they don't want people writing analytics packages for facebook but would prefer users to use the facebook system.
I know when it comes to images you can only get the number of likes , but not who they actually came from.
Your best bet is to use FQL which still lets you retrieve some of this information.
I know how to get someone's thumbnail via the Facebook API, but how do you get the person's full profile pic? What permissions are necessary to do this?
Append type=large to the query string. For example https://graph.facebook.com/100/picture?type=large
The full profile picture can not be retrieved via the user's picture connection (https://UID/picture?type=large will only return a picture of about 200x200).
To get the largest version of the profile picture stored on Facebook, you need to access the user's profile photo album. This requires user_photos permission.
The full profile picture can be retrieved by iterating over the albums, looking for the album which has the the type 'profile' and then getting its cover page:
public function getProfilePictureMaxUrl($facebook,$uid,$userAccessToken) {
$params = array('access_token' => $userAccessToken);
$r = $facebook->api('/'.$uid.'/albums',$params);
foreach ($r['data'] as $album) {
if ($album['type'] == 'profile') {
//retrieve information about this album
$r = $facebook->api('/'.$album['id'],$params);
$pid = ($r['cover_photo']);
//retrieve information about this photo
$r = $facebook->api('/'.$pid,$params);
return $r['source'];
}
}
//Profile folder not found (could be because of paging)
error_log('Failed to retrieve profile folder for uid '.$uid);
return false;
}