I have the following code.
public void PostToWall(string message, string targetId)
{
dynamic parameters = new ExpandoObject();
parameters.message = message;
parameters.target_id = targetId;
dynamic result = _fbApp.Api("/me/feed", parameters, HttpMethod.Post);
}
Which works fine when the targetId is the id of the user authenticated.
However, when targetId is that of one of the authenticated users friends it doesn't work.
Anyone have any idea why?
I would suspect because you're trying to post to your feed, not the friend - /me/feed
The FB GraphAPI specifies that you POST to http://graph.facebook.com/PROFILE_ID/feed.
Sorry to tell you, but you can't actually do this.
Facebook has change the privacy settings, so that you can't access your friends wall using an app
Please find the relevant info here
https://developers.facebook.com/roadmap/completed-changes/
(look for the change of February 6th)
Related
We are converting to Facebook's unity SDK and running into an issue downloading the profile images of friends. We are getting this error:
error getting user picture Failed downloading https://graph.facebook.com/#USERIDHER#/picture?type=square?access_token=#OURTOKENISHERE#
The app has permission for friends_photos. Is there another permission required for this?
I'm doing it using the code from the sample Friends Smash Application, while using the default permissions.
Get the list of the friends by using the Graph API and astore it in m_friendData dictionary:
FB.API("/me?fields=id,first_name,friends.limit(20).fields(first_name,id)", Facebook.HttpMethod.GET, GetFbFriendsCallback);
Retrieving the friend avatar:
FB.API(Util.GetPictureURL((string)m_friendData["id"], 96, 96), Facebook.HttpMethod.GET, this.FriendPictureCallback);
The callback which process the answer:
`public void FriendPictureCallback(FBResult result)
{
if (result.Error != null)
{
Debug.LogError(result.Error);
return;
}
friendAvatarImage.image = result.Texture;
}
`
Hope this helps.
This is apparently a known issue for the SDK and is being worked on since March 5th, see this reference:
https://developers.facebook.com/x/bugs/364606280347510/
I have an Instagram application written in Coldfusion 8 that basically pulls in media by tags and then allows people to Like / vote on the photos which is all done via the Instagram API. The Liking part is causing me no end of grief though, as I can get the Authentication and Access_Token without a drama, however the Access_Token doesn't appear to have permission to Like by default. There is an optional param for the Authenticate call "scope" which allows you to pass the permissions allowed for the Access_Token but i cannot work out how to pass this via ColdFusion CFHTTP as a POST.
Here is the preparation for the data to be sent over CFHTTP looping over all params as type="FormField". No matter how I try and present the scope options, either JSON format, string with spaces, string with "+" delimiters it seems to have no effect and the Like operation continues to fail due to permission errors.
<cfscript>
var LOCAL = {};
LOCAL['config'] = {};
LOCAL['returnStruct'] = {};
// prep packet required by the main call method
// the following values are required for EVERY call
LOCAL['config']['method'] = 'POST';
LOCAL['config']['format'] = ARGUMENTS['outputType'];
LOCAL['config']['url'] = VARIABLES.authURL;
// variables required by this method
LOCAL['config']['params'] = {};
LOCAL['config']['params']['client_secret'] = ARGUMENTS.client_secret;
LOCAL['config']['params']['grant_type'] = 'authorization_code';
LOCAL['config']['params']['redirect_uri'] = ARGUMENTS.redirect_uri;
LOCAL['config']['params']['code'] = ARGUMENTS.code;
LOCAL['config']['params']['scope'] = 'likes comments relationships';
</cfscript>
If anyone else is running into the same issues with "scope" not being correctly applied to the return Access_Token it turns out the problem was Instagram Documentation being vague about where this argument should be used. I had tried it every way possible as a POST operation as it suggested during the server-side Authentication, however it appears to only work if sent as GET params and after some playing around I decided to tack the "scope" param onto the 2nd stage of the authentication which is where the Code is requested and that worked! See below
https://api.instagram.com/oauth/authorize/?client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&response_type=code&scope=likes+basic
This will present the user with an confirmation message from Instagram to allow the application to perform Likes on behalf of the user and everything else works like a charm after this.
I have an application which I developed about a year ago and I'm
fetching facebook accounts like this:
facebookClient = new DefaultFacebookClient(access_token);
Connection<CategorizedFacebookType> con = facebookClient.fetchConnection("me/accounts", CategorizedFacebookType.class);
fbAccounts = con.getData();
It worked fine until about a month ago, but now it returns the
fbAccounts list empty. Why is that?
I was hoping moving from restfb-1.6.2.jar to restfb-1.6.9.jar would
help but no luck, it comes up empty on both.
What am I missing?
EDIT, to provide the code for another error I have with this API. The following code used to work:
String id = page.getFbPageID(); // (a valid facebook page id)
FBInsightsDaily daily = new FBInsightsDaily(); // an object holding some insights values
try {
Parameter param = Parameter.with("asdf", "asdf"); // seems like the param is required
JsonObject allValues = facebookClient.executeMultiquery(createQueries(date, id), JsonObject.class, param);
daily.setPageActiveUsersDaily((Integer)(((JsonArray)allValues.opt("page_active_users_daily")).getJsonObject(0)).opt("value"));
...
This throws the following exception:
com.restfb.json.JsonException: JsonArray[0] not found.
at com.restfb.json.JsonArray.get(JsonArray.java:252)
at com.restfb.json.JsonArray.getJsonObject(JsonArray.java:341)
Again, this used to work fine but now throws this.
You need the manage_pages permission from the user to access their list of adminned pages - a year ago I'm not sure you did - check that you're obtaining that permission from your users
{edit}
Some of the insights metrics were also deprecated, the specific values you're checking may no longer exist - https://developers.facebook.com/docs/reference/fql/insights/ should have the details of what is available now
Try to check your queries manually in the Graph API Explorer to eliminate any issues in your code and hopefully get more detailed error messages that your SDK may be swallowing
I try without success to execute a FQL query using Graph API to get the value of Insights counters.
Does anyone know how I can do this?
I use "Facebook C# SDK" version 5.4.1, C# 4.0.
If I use C# sample code provided in the documentation
var fb = new FacebookClient(m_accessToken);
dynamic result = fb.Query("SELECT name, uid FROM user WHERE uid= me()");
I receive a good response
{"name":"","uid":100002632407830}
With the same syntax, If I request "pages_fans" Insights counter and use library 5.4.1
var fb = new FacebookClient(m_accessToken);
dynamic result = fb.Query("SELECT metric, value FROM insights WHERE object_id=6176018219 AND metric='page_fans' AND end_time=end_time_date('2011-12-31') AND period=period('lifetime')");
I receive always an empty response
{[]}
With the same code but with library 5.2.1
I receive always a good response
{[{"metric":"page_fans","value":"125535"}]}
It is the same problem described here : Error with FQL query with library 5.4.1 but with another syntax.
Currently I use FQL Insights queries using REST API (with libary 5.2.1) but I want to migrate to FQL Insights queries using the Graph API (with library 5.4.1) because the REST API is deprecated.
Where is the bug:
In my syntax request?
In the "Facebook C# SDK" library?
On Facebook server?
Best regards.
I made a request with the Facebook Graph API Explorer
https://graph.facebook.com/fql?q=SELECT metric, value FROM insights
WHERE object_id=6176018219 AND metric='page_fans' AND
end_time=end_time_date('2011-12-31') AND period=period('lifetime')
I receive always an empty response.
{
"data": [
]
}
It is a Facebook's bug.
A bug was created about it on Facebook : http://developers.facebook.com/bugs/232510993491615?browse=search_4f08c675cce9d2265724293
I found another way to retrieving the info which works reliably
I found another way of retrieving insights which seems to be reliable.
documentation found here http://developers.facebook.com/docs/reference/api/insights/.
with more options to allow format and period changes - below example.
https://graph.facebook.com/2439131959/insights/application_active_users/[period]?format=json&since=[timestamp]&until=[timestamp]&access_token=[access_token]
period is day, month, week, lifetime.
timestamp has to be a valid PST midnight only.
access_token = could be.
1. nothing for the metrics that don't need permission.
2. app_id|secret_code or
3. your authentication token granted that you have access to the insight data of the application or pages (ie owner or insight users).
C# sdk example:
FacebookClient fbClient = new FacebookClient([appID], [secret]);
DateTime untilDate= (new DateTime([Now].Year, [Now].Month, [Now].Day));
DateTime sinceDate= (new DateTime([Now].Year, [Now].Month, [Now].Day)).AddDays(-1);
TimeSpan t = (untilDate- new DateTime(1970, 1, 1));
int timestampUntil = (int)t.TotalSeconds;
t = (sinceDate- new DateTime(1970, 1, 1));
int timeStampSince = (int)t.TotalSeconds;
var result = (IDictionary<string, object>)fbClient.Get([appID] + "/insights/" + [metricID] + "/" + [period] + "?format=json&since="+timeStampSince+"&until="+timestampUntil );
Console.WriteLine(result["data"]);
Make sure you have the correct permissions when you get your Access Token
<fb:login-button perms="read_insights"></fb:login-button>
This issue related to Facebook C# SDK.
Probably best thing you can do is file a bug on codeplex, and replace usage of end_time_date to "time in seconds" and period to "lifetime".
Using the current PHPSDK and API (ie not FBJS or the REST approach) I am trying to work out how to paste to a fanpage wall and struggling to find any hints...
I have successfully (through various attempts)
posted to my wall
posted to a friend's wall
posted to the page's wall (when I like the page before posting)
posted to the page's wall (as the page)
So I am looking to work out what I need to do to access_code/permissions or code to have something like :
$result = $facebook->api(
'/<PAGEID>/feed/',
'post',
array('access_token' => <ACCESSCODE>, 'message' => 'Test message')
);
or
FB.api('/<PAGEID>/feed', 'post', {access_token:<ACCESSCODE>, message:'Test message'},
function(response) {
if (!response || response.error) {
alert(response.error.message);
} else {
}
});
working where a post will appear on the feed of page's wall... However I am currently unable to find a way to post to a page wall for a page that I have not explicitly said I like by using the Graph API in PHP...
I am sure it is possible judging by some of the page walls I have seen.
Searching on google and forums tends to lead to old API implementations (which no longer function) or using methods no longer supported. It seemed that the Templatized function could have been what I was looking for (but again that has been deprecated).
What am I doing wrong?
You have to have one of the page administrators give your app "publish_stream" permission. Something like this:
$session = $facebook->getSession();
$perms = 'publish_stream';
echo '<fb:login-button perms="' . $perms . '"></fb:login-button>';
Once the click the button and approve you, your callback url will get called with their session information.
Once you have that you can post to the wall of any page they administer. Using code like what you show in your question.