I've encountered a problem during authenticating with Facebook. It's my simple login code:
<script src="https://www.gstatic.com/firebasejs/4.5.2/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "..."
};
firebase.initializeApp(config);
var provider = new firebase.auth.FacebookAuthProvider();
firebase.auth().signInWithPopup(provider).then(result =>{
var user = result.user;
console.log(user.photoURL);
});
Once I log in using the code above, I get a proper email, user, etc., but I get invalid photoURL:
https://scontent.fna.fbcdn.net/v/t1.0-1/p100x100/11214115_1018245048206356_1486864451318081978_n.jpg?oh=88cb39be27d4d329ab99ae0c426818d1&oe=5A8021D0
When I follow this URL I get an error:
Cannot find DNS address of server scontent.fna.fbcdn.net.
How could I retrieve the proper Facebook user photo URL?
I need to mention that google login works perfectly and returns valid photoURL.
Firebase auth with Facebook returns a invalid photoUrl in the currentUser object. However, you can use the providerData list object to get the correct photoUrl from your auth provider:
this.afAuth.auth.currentUser.providerData[0].photoURL
Please set this post as the correct answer. :)
I solved the problem by removing user and logging again. I could be a big issue in production environment.
I also found another workaround. The valid and invalid URL's are near the same:
valid one:
https://scontent.xx.fbcdn.net/v/t1.0-1/p100x100/11214115_1018245048206356_1486864451318081978_n.jpg?oh=88cb39be27d4d329ab99ae0c426818d1&oe=5A8021D0
invalid:
https://scontent.fna.fbcdn.net/v/t1.0-1/p100x100/11214115_1018245048206356_1486864451318081978_n.jpg?oh=88cb39be27d4d329ab99ae0c426818d1&oe=5A8021D0
So if you encounter the problem you need replace fna from host name to xx
Related
When I call the following url
https://graph.facebook.com/<page id>?fields=id,name,access_token&access_token=<long lived user token here>
I only get back the fields id and name, but not the field access_token:
{
"name": "<page name here>",
"id": "<page id here>"
}
Why is that? How can I get the page token with new experience?
I'm using the Payouts API and to do so I have to specify an access token when calling https://api-m.sandbox.paypal.com/v1/payments/payouts
To get an access token, as specified here I have to send a POST request with Postman to https://developer.paypal.com/docs/api/overview/#get-an-access-token and it returns in the response the token
My problem is that this token has an expiration time, which is an issue because I can't go in my app every 15 minutes to change the token in the Authorization header. How can I get a "permanent" or rather an "auto refreshed" token ?
I tried to make a call from my app instead of Postman but it doesn't seem to work, it says my credentials are invalid
This is my code in case it can be useful (I'm managing everything from the front-end):
window.paypal
.Buttons({
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [
{
description: this.product.description,
amount: {
value: this.product.price
}
}
]
});
},
onApprove: (data, actions) => {
const timestamp = new Date().getUTCMilliseconds();
const id = timestamp;
return actions.order.capture().then(details => {
axios
.post(
"https://api-m.sandbox.paypal.com/v1/payments/payouts",
{
sender_batch_header: {
sender_batch_id: id,
email_subject: "You have a payout!",
email_message:
"You have received a payout! Thanks for using our service!",
recipient_type: "EMAIL"
},
items: [
{
amount: {
value: this.product.price,
currency: "USD"
},
note: "congrats someone bought your stuff",
sender_item_id: id,
receiver: "john#doe.com"
}
]
},
{
headers: {
Authorization:
"Bearer <my token that I get from postman>"
}
}
)
.then(() => {
alert(
"Transaction completed by " + details.payer.name.given_name
);
})
.catch(err => console.log(err));
});
}
})
.render(".paypal");
}
},
Update
Reading the code a second time and noticing how your Payout is for the same this.product.price as the original payment, that makes no sense. Don't use payouts at all for this use case. The full amount will go to your account normally, but if you want the full amount to go somewhere else instead, set the payee variable for this checkout: https://developer.paypal.com/docs/checkout/integration-features/pay-another-account/
(original answer below)
Using Payouts from the client side is an absolutely terrible idea, anyone with your client credentials will be able to send money from your account to wherever they want
The payouts API must be used from your server only. Your server needs to do an API call to get an access token, similar to what you mention about postman -- except using whatever backend environment you have. You can integrate direct HTTPS calls, or there are also Payouts SDKs available which will handle getting the access token automatically.
As for how to trigger that backend action when capturing a payment, use a proper server integration:
Create two routes, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return JSON data. Before returning JSON data, that last route (the capture one) should record the successful transaction in your database and trigger any Payout logic you want.
Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
I'm trying to get all photos from my facebook pefil but all i got is a empty array data or only the perfil photo, i think that with could be my passport facebook error but with the facebook api im geting empty array too,
i try this,
https://graph.facebook.com/USERID/photos?access_token=USERTOKEN
i dont know what i'm doing wrong, i tried with photo type uploaded and doesn't work too, i just wanna all perfil photos.
reponse:
{
"data": []
}
If you are still receiving an empty array after obtaining the user_photos permission, try adding type=uploaded (options are uploaded or tagged), e.g.: /me/photos?fields=images&type=uploaded&access_token=...) or in the JS SDK:
FB.api("/me/photos", { fields: "images", type: "uploaded" }, (resp) => { console.log(resp) });
(Note you can always pass "me" instead of a user ID to get info for the current user)
I have problem with fb api.
FB.api('/me/likes/pageid',function(response) {
console.log(response.data);
});
i have
Object
category: "Entertainment"
created_time: "2012-09-17T16:56:56+0000"
id: "pageid"
name: "site.com"
but on one computer i have undefined Object { data=[0]}
I logged in on both in facebook. any ideas?
in FF i have
An active access token must be used to query information about the current user.
You have to specify a valid access_token
This is the right way to do that
FB.api('/me/likes/pageid', {access_token: "YOUR_ACCESS_TOKEN"}, function(response) {
console.log(response.data);
});
You have to add "user_likes" to the scope of your app to retrieve the result
I have a website and use the login using facebook.
I want to do the following:
User comes to my web site - login with facebook - I read his facebook data and photography permits
For example:
{
"id": "1"
"name": "John English"
"first_name": "John",
"last_name": "English"
"link": "https://www.facebook.com/johnenglish"
"username": "johnenglish"
"gender": "male"
"locale": "en_US"
....
}
and
{
"id": "2"
"name": "John English2"
"first_name": "John",
"last_name": "English2"
"link": "https://www.facebook.com/johnenglish2"
"username": "johnenglish2"
"gender": "male"
"locale": "en_US"
....
}
Both users have a private photo. Can I load the private photos from user (id: 2) with my web application using javascript? Can you give me the example?
I've tried this:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api('/USER-ID(USER ID 2)/photos?access_token=' + accessToken, function(response) {
//A user access token is required to request this resource.
});
} else if (response.status === 'not_authorized') {
} else {
}
});
Error: A user access token is required to request this resource.
Have you requested the right permissions when you gained your access token? I don't know how to do it in JS, but you have to tell facebook, that you want you get access to the photos. As I do not work with JS, I request my access token via an URL (see Point 1 here: https://developers.facebook.com/docs/authentication/devices/). In the parameter "scope" you can add the permissions you want to have ( https://developers.facebook.com/docs/authentication/permissions/). Here, you add "&scope=user_photos" (without quotation marks) to the URL.
OK, now I understand your question.
I assume that you already found out the ID of the User 2. I am sorry but I can still not show you how to do it in JS. Though, it may help.
At first, I forgot one permission, you need friends_photos in scope, too.
You now call: http://graph.facebook.com/FRIEND_ID/albums/?access_token=ACCESS_TOKEN.
Type it into your browser, so that you know what I mean: You parse that output and find ids of the albums of your friend.
You get to that album via: http://graph.facebook.com/ALBUM_ID?access_token=ACCESS_TOKEN.
You will find an entry named cover_photo in your output.
Call: http://graph.facebook.com/COVER_PHOTO_ID?access_token=ACCESS_TOKEN and you get access to that photo.
You may now download it via http://graph.facebook.com/COVER_PHOTO_ID/picture?access_token=ACCESS_TOKEN.
Use the URL given in paging -> next to move on to the following photos. It is much easier to follow these steps with a picture in mind, consider that here.