I have been trying to create groups on facebook using Facebook Graph api. After referring this site http://developers.facebook.com/docs/concepts/app-game-groups/#impl where they have mentioned on how to create groups, i have written following code. But it is not working.can u plz help me on how to create groups on facebook
code:-
Ext.Ajax.request ({
url : 'https://graph.facebook.com/342283535872845/groups/description?access_token=342283535872845|9Adi1Gb9qf2UpcZHu_NywK5bBxI',
dataType: 'json',
timeout: 60000,
type:'POST',
success: this.Success,
failure: this.Failure,
scope: this
});
},
Response :-
{
"data": [
]
}
The response should have group id but instead i am getting null data.
Please help me with this on how to create groups?
You need to be the admin of the application and you must have the app access token.
Here is the sample code
$app_token = $app_id."|".$app_secret ; This is how you can gain the app access token
$response = $facebook->api(
"/APPID/groups", "POST",array (
'access_token' => $app_token,'name' => 'TEST NAME',
)
);
Related
I just can't wrap my head around how the authentication is done if I use Firebase auth and I wish to connect it to my django rest backend.
I use the getIdTokenResult provided by firebase as such:
async login() {
this.error = null;
try {
const response = await firebase.auth().signInWithEmailAndPassword(this.email, this.password);
const token = await response.user.getIdTokenResult();
/*
No idea if this part below is correct
Should I create a custom django view for this part?
*/
fetch("/account/firebase/", {
method: "POST",
headers: {
"Content-Type": "application/json",
"HTTP_AUTHORIZATION": token.token,
},
body: JSON.stringify({ username: this.email, password: this.password }),
}).then((response) => response.json().then((data) => console.log(data)));
} catch (error) {
this.error = error;
}
},
The only thing I find in the firebase docs is this lackluster two line snippet: https://firebase.google.com/docs/auth/admin/verify-id-tokens#web
where they write
decoded_token = auth.verify_id_token(id_token)
uid = decoded_token['uid']
# wtf, where does this go?
# what do I do with this? Do I put it in a django View?
I found a guide here that connects django rest to firebase: https://www.oscaralsing.com/firebase-authentication-in-django/
But I still don't understand how its all tied together. When am I supposed to call this FirebaseAuthentication. Whenever I try to call the login function I just get a 403 CSRF verification failed. Request aborted.
This whole FirebaseAuthentication class provided by the guide I linked to above - should I add that as a path on the backend?
path("firebase/", FirebaseAuthentication, name="api-firebase"),
Which is the api endpoint my frontend calls?
I have a snippet of code in my Ionic 2 app that is supposed to grab the Facebook profile of the user after they have successfully logged on. I've verified that the request path /me returns data associated with the user, however when I set the request path to /me/picture, I get an error: There was an error making the graph call.
Here is my code:
if(this.platform.is('cordova')) {
Facebook.login([
'public_profile',
'user_friends',
'email'
]).then((result) => {
Facebook.api('/me?fields=id,name,email,cover', []).then(data => {
// Create the user object
let user = {
access_token: result.authResponse.accessToken,
display_name: data.name,
email: data.email,
facebook_id: data.id,
cover_photo: data.cover.source,
}
Facebook.api(`me/picture`, []).then(data => {
user['profile_photo'] = data.url;
this.loginWithFacebook(user);
}, error => { this.user = JSON.stringify(error)});
})
},
error => {
this.user = JSON.stringify(error);
})
}
Am I missing something? I've even tried doing /{user-id}/picture and still receive an error. Anyone run into this issue?
By default this edge will return a 302 redirect to the picture image. To get access to the data about the picture, please include redirect=false in your query.
Source: https://developers.facebook.com/docs/graph-api/reference/user/picture/
For example: Facebook.api('me/picture?redirect=false', [])...
I have the facebook page and all photos and albums are public.
I've used previously this query for get all albums:
https://graph.facebook.com/67695062976/albums
Now this query writes this error:
An access token is required to request this resource.
My javascript function for get all albums:
getAlbums: function()
{
$.get('http://graph.facebook.com/67695062976/albums?callback=?', {
}, function (res) {
$('#AlbumsContent').html("");
$.each(res.data, function (key, value) {
var image = res.data[key];
$('#AlbumsContent').append('<div class="PhotosAlbums"><a id="buttonPhotosAlbums'+image.id+'" href="album-'+image.id+'"></a><div class="PhotosAlbumsName">'+image.name+'</div></div>');
});
}, "json");
},
How can i fix this problem in javascript side?
You need an Access Token for almost everything now, for public stuff of pages you can just use an App Access Token, which is the App Id and The App Secret, combined with a pipe:
App-ID|App-Secret
There you go:
https://graph.facebook.com/67695062976/albums?access_token=App-ID|App-Secret
If you did not create an App yet, this is where you do it: https://developers.facebook.com/apps
Hi i created a plugin portlet. In the JSP i am accessing all countries list by using JSON API. It is working fine for Logged in users. But for the Guest users i am unable to access the web service. I am working on Liferay 6.0.6. The following is my code.
Liferay.Service.Portal.Country.getCountries(
{},
function(result) {
for(var count=0;count< result.length;count++){
alert(result[count].name);
var option = document.createElement("option");
}
}
);
Assuming that you are using Liferay 6.1, you can achieve it by adding a property to portal-ext.properties file
json.service.public.methods=getCountries
If you need to check the whole flow checkout
JSONServiceAction
I think you need to pass the serviceContext with permissions to the Service.
Can you try by setting the communityPermissions and guestPermissions as VIEW ?
Liferay.Service.Portal.Country.getCountries(
{
serviceContext: jQuery.toJSON(
{
communityPermissions: communityPermission,
guestPermissions: guestPermission,
scopeGroupId: themeDisplay.getScopeGroupId()
}
)
},
function(result) {
for(var count=0;count< result.length;count++){
alert(result[count].name);
var option = document.createElement("option");
}
}
);
I found a work around for the above problem. I am unable to access JSON API because Liferay is using A.io.request for AJAX Calls which is available for Logged in Users only. So I have prepared the following code.
jQuery.ajax({
type: "POST",
url: '<%=themeDisplay.getURLPortal() %>'+'/tunnel-web/json?serviceClassName=com.liferay.portal.service.CountryServiceUtil&serviceMethodName=getCountries',
dataType: 'json',
success: function(countriesList) {
alert(countriesList);
alert(countriesList[0].countryId);
}
}
});
i have:
user facebook data (
https://graph.facebook.com/btaylor )
facebook application data (
https://graph.facebook.com/2439131959
)
Is somehow possible to get if user is application administrator in facebook with this in my hands?
To get this kind of information you can use FQL:
protected function authorizeByFb(){
$result = $this->fb->api(array(
'method' => 'fql.query',
'query' => "SELECT developer_id FROM developer WHERE application_id='{$appId}' AND developer_id='{$fbUserId}'",
));
if(count($result)==1){
return true;
}
return false;
}
if your developed application is checking the role of the logged in facebook user or simply your application wants to recognize it's owner or admin,
then
http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Faccounts should have that application id listed
api call:
FB.api('/me/accounts', 'get', {"access_token":access_token}, function(response){
//loop through response to check any application id matches current application id
});
response sample:
{
"name": "app_name",
"access_token": "current_token_here",
"category": "Application",
"id": "your_owned_app_id"
},
{
"name": "app_name1",
"access_token": "current_token_here",
"category": "Application",
"id": "your_owned_app1_id"
},
I just got this to work using the Facebook JS API:
FB.api({ method: 'pages.isAdmin', page_id : fbAppId }, function(response){
if(response){
alert('the user is an admin');
}else{
alert('the user is not an admin')
}
});
It's using the FB.api method to access the old REST API. This assumes that you've already called FB.init, so make sure that this comes after your init code.
Cheers,
Jeremy
You can get the signed_request and then check if page_admin = 1
<?php
$signed_request = $facebook->getSignedRequest();
$page_admin = $signed_request["page"]["admin"];
if ( $page_admin == 1 ){
echo 'Welcome Admin!';
}
?>
I tried to attempted javascript form above and found this method to work as an alternative now that the old restful api is depreciated.
function checkAdmin(fbUID, fbAppID){
FB.api({
method: 'fql.query',
query: 'SELECT role FROM app_role WHERE developer_id ='+fbUID+' AND application_id = '+fbAppID
},
function(response) {
if(response.length){
alert('User is an Admin');
}
else{
alert('User is not an Admin')
}
});
}