I've put together a script, with the help of another SA post, but the issue I'm having is it's always returning error. When logging the error with console log it contains no properties so I can't determine why I am getting the error.
$(".add-image").click(function() {
FB.login(function(response) {
if (response.authResponse) {
var imgURL="http://farm4.staticflickr.com/3332/3451193407_b7f047f4b4_o.jpg";
FB.api('/album_id/photos', 'post', {
message:'Test',
url:imgURL
}, function(response){
if (!response || response.error) {
console.log(response);
} else {
alert('Post ID: ' + response.id);
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'publish_stream'});
});
I've created the app. Added the API ID when including the Javascript.
When running I get a pop up asking me to log in, and it seems to log me in without problems. But it returns an error when checking for a response or response.error.
Any advice.
Not sure if this is still a problem for you, but I've been looking into the same thing recently and I believe that, for this type of upload, FB basically requires source to be the image data itself, not a URL to the image. (See the create photos section on https://developers.facebook.com/docs/reference/api/album/ - it indicates that the source paramater must be multipart/form-data.)
So you have a few workarounds:
1) You may be able to do it from JS if you can create a custom Open Graph Object. I haven't tried this yet, but https://developers.facebook.com/docs/opengraph/usergeneratedphotos/ looks like it expects a URL rather than the post data itself.
2) If the image is originating on the user's computer, you can create an HTML form that submits to FB and have the image go directly from the user to FB without ever hitting your server. This blog post shows an example of that: https://developers.facebook.com/blog/post/498/
3) If the image is originating in your system, you can do a POST from your server to FB that mimics the above form. If it's somewhere else online (such as Flickr), you can download it to your system first and then POST it to FB. You'll have to include an access_token in the request. I don't know what language / framework you're using on your server, but there's probably a library to make creating POST requests easier.
Related
I created an Android App with PhoneGap:Build and the FB Connect Plugin. The app works fine and the FB Plugin, too. Just one tiny thing isn't working yet. I won't to post something after submiting a button which works, too. At the first time the user has to login and grant permissions to the FB App and them the post is published. That's the way it should be. And the next time the user submits the post should be published without the whole permission thing but this isn't working!? FB shows a message like "You already granted permission ... to the app." and the user has to push the Ok-button before the post is published???
Because I still haven't found an answer for my question, maybe I just do something wrong in my FB Javascript call? Here is the current code:
FB.login(function(response) {
if (response.authResponse) {
var data = {
...
}
FB.api('/me/feed', 'post', data, function(response) {
// Callback
if (!response || response.error) {
// ERROR
}
});
} else {
// ERROR
}
}, {scope: 'publish_stream'});
Well, to better understanding here a picture of the screen that apears every post:
http://i.stack.imgur.com/bZrde.png
Thx,
Daniel
I think the solution to this problem is to not include the login request every time you want to post something. You can check login status, and/or permissions, without performing a login. Then, if the user is not logged in, do the login first, and come back to the new post action.
I have a Facebook App (a game) that is perfectly working if I access the URLs directly (https://apps.facebook.com/[appnamespace]/ or https://mydomain.com/, the last one being the canvas URL).
But every time I submit the app for review I get the following feedback: "Please address the following feedback from our review team. Once you have made the changes listed below you may resubmit for review." and "Your app's Canvas page doesn't load".
Problem is I don't really know what to change because for me and for friends with whom I shared the link it's working as expected.
I have only one error in the console in Chrome which is:
"Unsafe JavaScript attempt to access frame with URL https://apps.facebook.com/[appnamespace]/ from frame with URL https://mydomain.com/. The frame being accessed set 'document.domain' to 'facebook.com', but the frame requesting access did not. Both must set 'document.domain' to the same value to allow access.
I don't have document.domain specified in my page though I tried some values before to get rid of this error message without success. And every time I set a value for document.domain I get another error in the console: "Uncaught Error: SecurityError: DOM Exception 18".
I didn't find anything on this that is working.
So any help/hint would be appreciated. I also tried to ask for more detailed feedback in the review description message but I still get the same message with no clue on how to solve the problem.
Thanks.
So I finally solved the issue.
The problem was that I didn't test the app when the user is not connected to Facebook. For me the app was not supposed to be used outside Facebook game center (though it's possible) and Facebook probably test this case during app review. Hence none of the following events gets fired:
auth.statusChange
auth.authResponseChange
auth.login
To tackle this problem I make a call to getLoginStatus, something like this:
FB.getLoginStatus(function (response) {
console.log('[Facebook] getLoginStatus: ' + response.status);
if (response.status !== 'connected' &&
response.status !== 'not_authorized')
{
console.log('[Facebook] not connected');
$('#loginscreen').show();
$('#btn-fb-login').click(function (event) {
event.preventDefault();
FB.login(function (response) {
$('#loginscreen').hide();
start(response);
}, { scope: 'email,publish_actions'});
});
}
});
I need to record to the database if a user likes an iframe page tab using the official Facebook 'like' button at the top. I did a search here at stackoverflow and found a javascript snippet ...
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
}
);
But it doesn't fire for the official button (only like buttons added to the page)? I declare it after FB.init and before FB.Canvas resize inside the asynchronous call. Is there a way in PHP to capture this - possible on refresh? Either JS or PHP is okay (since JS can simply ajax a php file). The signed request contains whether they like the page or not but I need to capture it as it happens (or just happened).
Any help greatly appreciated :-)
Try :
window.fbAsyncInit = function () {
FB.Event.subscribe('edge.create', function (targetUrl) {
_gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);
});
};
I think you just need to setup the subscript inside the fbAsyncInit.
Did it a purely PHP way in the end.
1: Get the signed request from facebook and extract the liked stats
2: Create a variable $liked and set to "yes" or "no" based on signed request value
3: Manipulate a session - use a session because the page gets refreshed when you "like" but the session remains (but the request value will have changed)
if(isset($_SESSION['likestatus'])){
if($_SESSION['likestatus'] == "no" && $liked == "yes"){
// do mysql updatestuff cause has liked page since session started
$_SESSION['likestatus'] = $liked;
}
else{
$_SESSION['likestatus'] = $liked;
}
}
else {
$_SESSION['likestatus'] = $liked;
}
I am wondering if it is possible to post through a Facebook app to an associated page as if the post was done on the page itself. I.e. if I am logged onto Facebook and I go to a page I am admin for, then when I post it will appear with the name of the page rather than my Facebook name. I would like to replicate this behaviour but coming from an external website connecting through a Facebook app. I have made all of the connections and I am able to post ok but it is coming through as my name. I am using the Javascript API with the following to login:
FB.login(function(response) {//do some login processing},
{scope: 'publish_stream'});
Then I publish the message with the following after logging in and accepting the permissions:
FB.api('/[PAGE NAME]/feed', 'post', { message: Text to post }, function(response) {
if (!response || response.error) {
alert('Error occurred '+response.error.message);
} else {
alert('Post ID: ' + response.id);
}
});
My Facebook App has the Site URL and App Domain set correctly and I have setup the App as a Page Tab and combined that to my page.
So if anyone can let me know if it is possible and how to do it, it would be greatly appreciated
Thanks
It's all about Authentication, you have a User Access Token but you need a Page Access Token to authenticate as a page.
Here is the doc: https://developers.facebook.com/docs/authentication/pages/
I can't seem to get a post to work for our news items as FB News items. I was able to create a whole custom type and I discovered the News specific option after I had implemented a standard object:action setup successfully so conceptually this should work since we had all the pieces working before.
Originally we (GlobalPost) created out own app and Auth for our own name space gp_storyshare for our article object with a action read.
Then I ran over this
https://developers.facebook.com/docs/opengraph/news/
and sighed, since it wasn't linked to any of the other documentation and started over. Here is where I'm at.
Since then I have added in all the news specific OG tags and altered our og type to
without any name space
see good example page with tags here
http://www.globalpost.com/dispatch/news/regions/asia-pacific/111206/burma-myanmar-aung-san-suu-kyi
I have not done anything to our App, not sure if I need to make any auth changes or anything as the developer page says nothing and the object isn't mine to control. ** I have a feeling this is the issue but no real proof.**
on window.load I call newsRead() seen below, like I did before. This doesn't work.
function newsRead()
{
FB.api('/me/news:reads' +
'?article=http://www.globalpost.com/$node->path','post',
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post was successful! Action ID: ' + response.id);
}
});
I just have no idea what to try next. Any help is appreciated.
For any of the open graph actions (including built-in) you'll need the publish_actions permission, but it's still in beta at the moment and will only work for registered developers and testers of the app - I'm not aware of any other specific restrictions, but I think you're probably going to be posting 'Article' objects ( https://developers.facebook.com/docs/beta/opengraph/objects/builtin/ )