need help implementing facebook credits - php

I've read a few of the other posts on getting started with implementing Facebook credits and I've downloaded the sample code from github: https://github.com/facebook/credits-api-sample.
The only changes I had made to the sample code are:
In index.php, I set the app ID.
In callback.php, I set the app secret.
I've uploaded all these files to my server:
index.php
callback.php
facebook.php
facebookapi_php5_restlib.php
xd_receiver.html
assets folder
On the Facebook app edit page:
The canvas url points to index.php.
The credits callback field points to the callback.php file on my
server.
Added myself as a credits tester.
I have not registered my company. Is that required for testing?
I do not have a secure canvas url. Is that required? The app is in sandbox mode.
When I run the test app, I see the index page. When I click on the "Pay with Facebook" button, this error pops up:
There was a problem processing your payment. Sorry, but we're having trouble processing your payment. You have not been charged for this transaction. Please try again.
When I close the dialog, there is a message:
Transaction failed!
Error message returned from Facebook:
The entity (class EntApplication) backed by id cannot be seen by the
current viewer 0 (EntID: )
Can someone please tell me what I am doing wrong?

I found out what the problems were:
In order to get this to work, you need to have the company registration filled out.
After that is done (and this was not obvious), you need to actually select the company from the drop down list. This is all done in the credits section.
You must have a secure canvas url set in the basic settings section (i.e. https://example.com/app/index.html)
I'm not sure if you have to have the callback as a secure url in order for the test to work, but it does make sense that this would be required.
The test will not work in sandbox mode.
Hopefully this will help others that may run into similar problems.
Now I have to figure out how to get this to work using the facebook-actionscript sdk.

Related

Auto-Publication with Facebook API

I have a client who has recently raised a problem of self publishing articles facebook. The client has created his application that seems correctly configured but the publication does not appear on his page. The message sent back by the facebook API is the following: (# 100) Parameters of the URL have the ability to specify the picture, name, thumbnail or description.
The Oauth connection is running correctly, the problem is with the publication.
To perform tests on my side, I became an administrator on its facebook application and then filled in my own page created for a long time already. No problem to publish on my personal page with the API facebook. I created a second page always with the same account then changed the url of the page on which to publish and I reproduce the problem. There seems to be a problem checking the user's rights on the page.
While searching on Google, I could find that is a security implemented on version 2.11 of the API with the domains but I did not find any way to solve my problem. Does anyone have a solution? Why I can publish on old pages but not on new pages created from the same account.
Thank you in advance for your assistance and sorry for bad english :)

Where do I have to place the code returned by Google oAuth after I grant access to an installed application, using PHP?

This has been a nightmare to get right for the past few days. First I was struggling with redirect_uri_mismatch errors, or bad requests, but now that I thought I nailed it, I'm getting this message from Google after clicking the "Allow" button in the consent screen :
Please copy this code, switch to your application and paste it there
Where exactly do I need to paste this code? I'm using PHP in a web server, I went to the "Other" application type when creating the credentials, because I read that this was preferred if I didn't want my users to keep getting that auth link.
I can't seem to find a concrete example of how to do this, I got it working this far by grabbing bits from here and there, but this one I just can't figure it out.
https://gist.github.com/andruxnet/0f7fe237730c13846a690da12935a708
I'm using a file client_secret.json that I downloaded from Google's oAuth credentials screen, it looks like this:
{"installed":{"client_id":"xxxxxxxxxxxxxxx.apps.googleusercontent.com","project_id":"my-project-id","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"xxxxxxxxxxx","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
Anyone knows what else I need to do or where to put that code returned from Google after the consent screen?
Thanks
Although the answer here does not use PHP, I still think it's worth to add it here as it's the only complete working example of how to update a youtube video without displaying the consent screen to the user, at least I wasn't able to find a concrete working example.
I ended up using the Javascript library, I still wasn't able to find a single complete example, not even in the library docs, nor Google's, it took taking pieces of code from here and there, and connecting the dots.
First thing to do is to create the credentials, we do this by going to Google developer console, and under Credentials we create a new OAuth Client ID, choosing Web Application and adding our domain to the Authorized JavaScript origins field - eg. http://www.example.com
The only information we will need from these credentials is the Client ID, so we copy it and paste it in the Javascript file below.
Here's the HTML part, where we also load the API library:
<input type="button" id="make-private" value="private" /> Make video private
<input type="button" id="make-public" value="public" /> Make video public
Current privacy status: <span id="current-status"></span>
<script type="text/javascript" src="update.js"></script>
<script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>
This is the Javascript code to make it happen - update.js in the code above, remember to update with your own client ID: https://gist.github.com/andruxnet/2efe7898f5cd9722e0d42b71fce5d183
The relevant Javascript code, once we figure out the authentication part that can be found in several places online, is this piece of code:
// we first grab the video resource from Youtube, using youtube video id
var request = gapi.client.youtube.videos.list({
id: 'youtubevideoid',
part: 'status'
});
// once we get the video resource, we update the status and
// run the update method
request.execute(function(response) {
// since we looked for a video id, we only got one result - the first
// and only item in the array of result items
video = response.result.items[0];
// set the privacy status to one of public, private or unlisted
video.status.privacyStatus = 'private';
// prepare the update with the new privacy status
var updateRequest = gapi.client.youtube.videos.update({
part: 'status',
fields: 'status',
resource: video
});
// execute the update - I didn't see this part in the API documentation,
// I found it somewhere else in SO as part of another question, although
// I should've figured it out by looking at the first list() method above
updateRequest.execute();
});
I hope this saves someone's time in the future as it would have saved my own.
Cheers
I see disinformation, go and check this link:
https://developers.google.com/api-client-library/php/auth/web-app#example
There you have many examples of what you are requesting, anyway the code you are receiving from google is the Auth Code which allows you to authenticate the client (The Google_client->authenticate(AuthCode) created in you php app to be more exact), after that you can start using their services with Accesstoken or RefreshTokens depending on what type of connection you requested to generete the perms.
I hope this comment help you a bit with the nightmare of developing Google Services :)

Redirecting to authentication dialog - "An error occurred. Please try again later"

Why does it always happen to me?
This happens after my application verify for user user login and redirect user to the authentication page:
https://www.facebook.com/dialog/oauth?client_id=XXX&redirect_uri=http%3A%2F%2Fexample.com%2Fmyappname%2F&state=YYYYYY&scope=offline_access%2Cpublish_actions
But instead of showing the authorization page, Facebook shows an error page with
An error occurred. Please try again later.
Is there any configuration I have to do before try to authenticate my users?
All is done with PHP using the PHP-SDK classes.
I have had the same problem as you.
From the Facebook Developers Apps page, make sure that the Sandbox Mode is disabled.
I had the same problem after changing the domain of my site. Altough I properly changed the request_uri parameter and updated my app settings with the new domain, the error kept showing up.
Then I realized that the ID and the SECRET ID of my Facebook APP had automatically changed with no warning!! The whole thing started working again using the new ID.
This was happening to me also but all the api keys, secrets and stuff were correct. What I found is that my app was running in sandbox mode. Go to your app settings in https://developers.facebook.com/ click the advanced settings tab and check to see if your app is in sandbox mode. If it is disable it and try again. Let us know if it works.
I was getting this error because I was starting from http://mysite.com, but had specified http://WWW.mysite.com in my Facebook settings - the www mattered... I ended up solving by using .httpaccess to always kill the "www", and pointing FB to http://mysite.com
worst. subdomain. ever. :u)
When working with Dialogues, Facebook provide a 'show_error' attribute that defaults to no but can be set to true in a Development environment and is really helpful for debugging purposes.
show_error - If this is set to true, the error code and error description will be displayed in the event of an error.
Instructions of it's use can be found in the Facebook Docs.
I'd been debugging "An Error occurred. Please try later." dialogue before i found this attribute in the docs. Once i started using it, i could see the following message too:
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: redirect_uri is not owned by the application.
I had the same problem; it turned out FB requires a string appID and not an int...
//DOESNT WORK:
$facebook = new Facebook(array(
'appId' => 147XXXXXXXXXXX,
'secret' => 'XXXXXXXXXXXXXX',
));
// WORKS:
$facebook = new Facebook(array(
'appId' => '147XXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXX',
));
For me this happened because the "test user" I created was part of a separate app. I created a test user for THIS app, and it started working fine.
Stupid on my part I know, but this could save someone else some trouble.
Make sure your app is configured to use the appropriate URL & domain of your site. That may be it.
According to OAUTH Dialog documentation:
*redirect_uri: The URL to redirect to after the user clicks a button in the dialog. The URL you specify must be a URL of with the same Base Domain as specified in your app's settings, a Canvas URL of the form https://apps.facebook.com/YOUR_APP_NAMESPACE ...*
I am constructing oauth links dynamically to ask a user for additional permissions if needed and I realized, that even if you are redirecting to https://apps.facebook.com/YOUR_APP_NAMESPACE you have to have the App Domain and Website settings set in your application administration. I set domain to facebook.com and Website to facebooks root url.
Now my oauth dialog link works fine - even in sandbox mode.
I had this exact problem on a Page Tab app and for the life of me couldn't work out what the problem was. It worked on my test page but as soon as I made it live it wouldn't work. I found in the end that I fixed the problem by putting the actual URL to the Page Tab (i.e. http://www.facebook.com/<"page_name">/app_<"app_id">) into "Site URL" under "Website". This doesn't make any sense. But it worked :-)
Solution for me is to set option 'Authenticated Referrals' to enabled. Its realy fixed after that.
The issue resolved after I updated the 'appID' and 'secret' and then pushed the change back to heroku (i.e. - 'git push heroku master')
The key is not to forget to push the changes back to heroku master. Very easy to overlook if you're use to testing on localhost.
Hope this helps.
For me the problem was that the Facebook users I was using to test the app did not have its email address confirmed by Facebook.
My client had set up 2 fake accounts on Facebook and told me that they were not working. But he forgot to confirm the email addresses of those accounts (the emails Facebook sent went to his spam folder and he didn't notice).
Took me hours to find this, so I hope it helps somebody.
Cheers!
Also had a problem with wrong redirect link: I had a link starting with "https://apps.facebook.com?myapplication".... but after authorization the redirection would bring me to "apps.facebook.com/Myapplication" and consequently I would get a message described above:"Error occured. Try back later." since "apps.facebook.com"... means "http://apps.facebook.com/Myapp" and not "HTTPS://apps.facebook.com/,..."
The solution: went to my application settings in facebook developers section. Clicked 'Edit'. In the left-side Menu selected "Permissions" (by default the Menu is set to Basic) and in the newly opened set of setting changed my "Auth Token Parameter" from "Query string" to "URL Fragment".
It worked! After authorization is finished the users are taken to "https://apps.facebook.com/myapp..."
Another possible mistake, if you directly copied the code from Facebook SDK example then you may get the same error despite of having everything correct. http://developers.facebook.com/docs/reference/php/
This is because in their example they have used backquotes instead of single quotes for the key of the array. The correct code is as follows.
require_once("facebook.php");
$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
If your all code is working properly then to remove such type of error go to Facebook Developers Apps and disable sandbox mode.
I just encountered this problem myself. I'm developing an app internally, so my host is 'localhost'. It wasn't obvious how to set 'localhost' up in the app configuration. If you want to develop locally, set up your app by following these steps:
Go to the place where you manage your Facebook app. Specifically, you want to be in "Basic" under the "Settings" menu.
Add 'localhost' to "App Domain".
Under "Select how your app integrates with Facebook", select "Website", and enter "http://localhost/".
Save and wait a couple of minutes for the information to propagate, although it worked right away for me.
I had put the restriction on the app that only United States residence could use the app. I was working from Canada at the time this error message appeared. After removing the restriction everything worked.
Came here with a similar problem and, yes, my Sandbox was enabled. I disabled it and, voila, the login problem went away. I must warn that this problem does not affect developers and website administrators as Facebook allows those users to see the app. For this reason, I couldn't even believe that users complained about not being able to login, as I was able to login with no problems at all.
I had the same problem, and fix it by adding param &display=touch to url
try, it may helps
Answer for 2015
Sandbox mode is gone.
Proceed to My Apps -> Your App -> Status & Review and change the slider to yes for:
Do you want to make this app and all its live features available to the general public?
If you're the app developer, you may see a more specific error message, but generally that message means one of two things:
Your server returned a HTTP error code (usually 5xx)
You tried to send the user, after login, to a URL not allowed by your app configuration (though as an Admin of the app, you should see a more specific error message and Facebook error code in this case)
I had this error because I was using redirect_url as a parameter instead of redirect_uri.
The Server-Side Authentication doc page says to use redirect_url:
https://www.facebook.com/dialog/oauth?
client_id=YOUR_APP_ID
&redirect_url=YOUR_REDIRECT_URI
&scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES
&state=SOME_ARBITRARY_BUT_UNIQUE_STRING
But this is incorrect. The OAuth Dialog doc says to use redirect_uri instead, which works, so I'm assuming that you can only use one and not the other:
https://www.facebook.com/dialog/oauth/?
client_id=YOUR_APP_ID
&redirect_uri=YOUR_REDIRECT_URL
&state=YOUR_STATE_VALUE
&scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES
I had tried all the answers mentioned here. But it didn't work. I had to delete and create again. I am guessing it was due to new the "Authenticated Referral". If you have added Open Graph objects which are not approved, it might give you an error.
I had the same problem and the root cause was different:
I was logged in as a Test User of a different application. Therefore I wasn't able to authorize an app that's not the one where the Test User was created for.
When I logged out and logged in as a regular user or a Test User for the app I tried to authorize, everything was OK.
In my case, there was an age issue with the account being used with the app.
If the FB app has alcoholic content then FB users who are younger than about 21 will throw an error when trying to authorize with it.
You need to specify http:// in your REDIRECT URI.
For me the issue was that the url of the app didn't completely match the url I was running it on (i.e different directories, same domain)
There is no possibility to solve this type of error. So Its better to use your custom dialog same like shown in facebook and post message again & again without login. Even though you remove your app from facebook, you can ask for login and post message successfully.
The reason in my case was completely different. I was trying to open a Feed dialog automatically after page load. And 9 times of 10 it displayed this error. First, I added show_error: true parameter as suggested by #Peter Roome, but it didn't help, displaying 104: Invalid signature, not descriptive at all.
Then I figured out the reason. The code was in $(document).ready jQuery function. And it seems that some facebook stuff had not yet been loaded at the point the code was to be executed. I moved the code to $(window).load block (which is executed after all page content is loaded), and the problem has been solved.

PHP: How to upload videos to YouTube without using a login?

I have a site and I want to upload videos onto YouTube without a login. Is it possibe? If yes, how can do this?
Create an account and use its credentials all the time, for all users of your site. You simply can't upload a video without a user account 'responsible' for it. #Pekka: ask for forgiveness, not for permission? ;)
Google at least has a youtube API (with uploading capabilities and PHP examples) right here: http://code.google.com/apis/youtube/2.0/developers_guide_php.html#Uploading_Videos
It is not possible to upload Video to YouTube without logging in.
That said, I wouldn't be surprised if even automated uploading with a login would be forbidden by YouTube's Terms and Conditions.
There is a way to do that without zend client library. Its in core php (PHP4).
https://github.com/techie28/YouTubeUploadPHP.
Note: AuthSub is deprecated now.Please refer to Google Deprecated policy for details.
EDIT:
Because codershelpingcoders.com now points to godaddy's parking page and the original link zendtutorials.wordpress.com has an empty article linking to codershelpingcoders.com, I found the original article via the archive: http://web.archive.org/web/20130123044500/http://codershelpingcoders.com/ and have tried to replicate it's contents in this answer for future reference (NOTE: I have no idea if this info still works).
This tutorial describes the direct browser based upload technique using AuthSub.
AuthSub is the Authorization module of the YouTube that lets your application interact with the YouTube for specific purposes such as Uploading videos etc on user’s behalf.
It is same like Auth and a cousin of oAuth.
A user grants the privilege to your site application and you can do the job on his behalf as simple as that.
We will go through the way to upload a video using AuthSub.
It goes as follows and can be really done in following 4 simple steps:
To allow the application run on user behalf a user must have
authorized it first.
So our first step to implement is to get the app Authorized by the user.
We do it by simply redirecting user to the authorization page the url
is as follows:
$nextUrl = urlencode(‘http://www.xxxx.com’)
$scope = urlencode(‘http://gdata.youtube.com’);
https://www.google.com/accounts/AuthSubRequest?next=’.$nextUrl.’&scope=’.$scope.’&session=1&secure=0
The nextUrl here is the url of the your application where the user
will be redirected after authorization procedure.
scope is to tell the YouTube about the scope of the process which is google
data youtube in this case.
So if user has not authorized your app yet he must be redirected to
the above mentioned authorization page once the user has approved
your application it needs not to follow the step one ever again until
and unless the user revokes the access to you app from the users
control panel of his account.
On successful completion of the authorization process user will be
redirected to your application and this complete the first step of
AuthSub.
If from the first step the user authenticates your application
YouTube will redirect him back to your application with a token in the url.
You are going to use this token and here is where the actual AuthSub process
comes into play you are going to use this token to obtain an entity called
AuthSubSessionToken which will allow you to interact your app to YouTube
on the user behalf who has just approved your application.
In PHP you do it by issuing a curl request. The details are as follows:
Issue a curl GET request to https://www.google.com/accounts/AuthSubSessionToken
with the token you received just after the authorization step.
Remember to turn ON the curl’s response gathering status as you gonna need that.
If everything went well till now you would be responded from YouTube with
the AuthSubSessionToken.
BINGO :-)
Now when you have received the AuthSubSessionToken you are gonna use
that to get an upload token which will actually upload the data
related to your video to YouTube i.e.title,description,category and
keywords. This is kinda reverse process as in AuthSub you upload the
data related to the video to YouTube first and then upload the video
itself. The uploading of video data also referred as MetaData will be
done by feeding XML to the YouTube,the xml will be:
title goes here
description goes here
category goes here
Keyword goes here
and again curl has business to do you will upload this by issuing another curl call:
url:http://gdata.youtube.com/action/GetUploadToken
headers:AuthSub token=”Your AuthSubSession token goes here”
GData-Version:2
‘X-GData-Key: key=”Your Api key goes here”
Content-length: length of the xml you formed above goes here
Content-Type:application/atom+xml; charset=UTF-8
POSTFIELDS: the xml itself that you formed
If the step 3 completes successfully then its time to upload the
video actually on your successful last curl execution you will be
reverted back by the YouTube with a url an a token.
Now you will create a form which will have this url as its action and token
as a hidden field something like this.
Just select the video and click submit and your video will get uploaded.
On successful submission you will be redirected back with status 200.
The github link for the Sample code is here.

How to update a user's Facebook status?

I looked at many similar questions here at Stackoverflow.com and searched in Google but still could not find an answer, so I am posting this new question.
I have a 3rd party PHP5 website in which users can write a short message. I want to have the ability for the user to click a button to share that message as a facebook status.
It is in my understanding that this can be done using the Facebook API and Users.setStatus. I am not sure where to begin though - do I implement Facebook connect in my site? I don't need anything but that ability, so I don't need a facebook 'canvas' page.
Do I start an application?
Could someone point me in the right direction?
Thanks!
You need to:
Create an application, paying particular attention to the Connect settings
Integrate your site with Facebook
Connect
Check the user has granted the
application the status_update
extended permission, and if not
pop up the permission dialogue
Use the Status.set API call
The details for each step are far too big for one SO answer, but hopefully that's a "point in the right direction".
You'll need to create a facebook application in order to set someone's status with Users.setStatus. You should keep in mind that users will have to install your application and allow it to publish on their behalf before you can do so, though.
Check out developer.facebook.com to get started.

Categories