How to retrieve all user fields with application access token? - facebook-graph-api

As per documentation of Facebook of Using App Access Token,
While an App Access Token is largely for the purposes of publishing information back to Facebook on behalf of the user, there is a limited set of information that can be retrieved from Facebook using an App Access Token.
Basic Profile Info of a User (ID, Name, Username, Gender)
A User’s Friends and their IDs
Permissions granted by the User to your App
ref : developers.facebook.com/docs/opengraph/using-app-tokens/
But I am not able to get mostly fields by application access_token.
I provide all user and friends permissions and extended permissions to a user with ID UID1
checked as : https://graph.facebook.com/UID1/permissions?access_token=APP_ACCESS_TOKEN
and I got : ( 1 signifies permission granted and 0 signifies permission not granted.)
{
"data": [
{
"installed": 1,
"read_stream": 1,
"manage_friendlists": 1,
"read_mailbox": 1,
"publish_checkins": 1,
"status_update": 1,
"photo_upload": 1,
"video_upload": 1,
"create_event": 1,
"rsvp_event": 1,
"email": 1,
"xmpp_login": 1,
"create_note": 1,
"share_item": 1,
"publish_stream": 1,
"ads_management": 1,
"read_insights": 1,
"read_requests": 1,
"manage_notifications": 1,
"read_friendlists": 1,
"publish_actions": 1,
"user_birthday": 1,
"user_religion_politics": 1,
"user_relationships": 1,
"user_relationship_details": 1,
"user_location": 1,
"user_likes": 1,
"user_activities": 1,
"user_interests": 1,
"user_education_history": 1,
"user_online_presence": 1,
"user_groups": 1,
"user_events": 1,
"user_photos": 1,
"user_notes": 1,
"user_questions": 1,
"user_about_me": 1,
"user_status": 1,
"friends_birthday": 1,
"friends_religion_politics": 1,
"friends_relationships": 1,
"friends_relationship_details": 1,
"friends_location": 1,
"friends_likes": 1,
"friends_activities": 1,
"friends_interests": 1,
"friends_education_history": 1,
"friends_online_presence": 1,
"friends_groups": 1,
"friends_events": 1,
"friends_photos": 1,
"friends_notes": 1,
"friends_questions": 1,
"friends_about_me": 1,
"friends_status": 1
}
]
}
Then I make a API call to following URL with APP_ACCESS_TOKEN to retrieve all possible information
https://graph.facebook.com/UID1?fields=id,name,picture,gender,locale,languages,link,username,third_party_id,installed,timezone,updated_time,verified,bio,birthday,cover,currency,education,email,hometown,interested_in,location,political,religion,website,work,relationship_status&access_token=APP_ACCESS_TOKEN
As a result I got only
{ id, name, gender, locale, username, third_party_id, installed, cover, email and picture }.
Out of which I am able to get
{ id, name, gender, locale, username, cover and picture } without any access_token.
But Facebook server is not at all sending me all other fields
{ location, birthday, relationship_status,languages,link,updated_time,bio,education,hometown,political,religion,work }
for which user has authorized the application. Now app_access_token is working fine (I hope so), Thats why I am able to get
{ email, installed and third_party_id }
but how to get rest fields. Please help me out of the same.

Related

I want to parse blockchain.info API info

First, thanks for anyone that can help me with this.
I work in bitcoin research, and I use blockchain.com API to retrieve some of the information about bitcoin transactions.
as an example, if I extract the transactions for the address 1ADSb1ZZ9k3NsDf3JTQCQ4mb8bthiAN6NJ, I get four records, and one of them is
the transaction https://www.blockchain.com/btc/tx/69b98a4476767e6fc40f8c33b3aec7fe83b7a7d3f8c7e92203b00c6be5afbdb3
My question, how do I know exactly from the returned fields the address 1ADSb1ZZ9k3NsDf3JTQCQ4mb8bthiAN6NJ paid to which address in the output side?
and what is the meaning for the fields in the returned results like n, tx_index, etc.
the raw data can be accessed through the website https://blockchain.info/rawaddr/1ADSb1ZZ9k3NsDf3JTQCQ4mb8bthiAN6NJ
So in short terms, I want to understand more about the fields meaning and how to track the payments of a specific address to which address as in the example on the transactions attached, how can I recognize each address sent money to any address..
{'block_height': 598496,
'block_index': 0,
'hash': '69b98a4476767e6fc40f8c33b3aec7fe83b7a7d3f8c7e92203b00c6be5afbdb3',
'inputs': [{'prev_out': {'addr': '1ELHDQXk9oFN3oNekrjsuEgdgs9PREhbP8',
'n': 0,
'script': '76a914923f12b92a44b2bebdee1629dc56b10b1551875b88ac',
'spending_outpoints': [{'n': 0,
'tx_index': 0}],
'spent': True,
'tx_index': 0,
'type': 0,
'value': 342000},
'script': '483045022100ca541d97ac125eab86d1bb7d8cbd57badbaeb03b4a5ca8c3ffb09e6f4287250a02204cc8974b28d2d9d011fab69aa71931078e3fd7b161e8fa00f0529c0202d0c958012102fa53aa0f511a3f17ee404af88c25437efafe22043e2648ca9c84540d0cbfbfc3',
'sequence': 4294967295,
'witness': ''},
{'prev_out': {'addr': '1LcxEYYTmZzpFBT1NRjMHJaPxQdoqjRUNz',
'n': 1,
'script': '76a914d7370e1fa4287252343681b303ffa0ae49aae67488ac',
'spending_outpoints': [{'n': 0,
'tx_index': 0}],
'spent': True,
'tx_index': 0,
'type': 0,
'value': 342000},
'script': '4730440220039c37fd0c0bb6ed6ee8e4d85fdb9b48d26b4d94d9df837e401ab98aaca0495a0220181248ddd1a42e57cea6a5b5f81fa52459c342c24494f72e633d7aa8fe32fd850121028402d935c4360218ff7a1471b0b465e5aacda16e44a9768e19062fd7c5e08701',
'sequence': 4294967295,
'witness': ''},
{'prev_out': {'addr': '1ADSb1ZZ9k3NsDf3JTQCQ4mb8bthiAN6NJ',
'n': 1,
'script': '76a91465137b65f80173c7fd3dcb898f40fd3fed243c7988ac',
'spending_outpoints': [{'n': 0,
'tx_index': 0}],
'spent': True,
'tx_index': 0,
'type': 0,
'value': 342000},
'script': '47304402201f984f7dccb2e536e22e896b3220c84b84cece5327c73a85da8bc6b8dca41bcc022045aa417d039f611779f5603f944e28e7a26094e8a8db44d5c1eb21f36e65ebb9012102b039f2a05824c9172f35a4548732e03724d88283241becc72d0dc2fbef18787c',
'sequence': 4294967295,
'witness': ''},
{'prev_out': {'addr': '1AMk76C3A8pLCfzm9YzaR3x2bdt9RZpNMw',
'n': 0,
'script': '76a91466a56efb73d51f5da3ba4e417f1da6f72d75053488ac',
'spending_outpoints': [{'n': 0,
'tx_index': 0}],
'spent': True,
'tx_index': 0,
'type': 0,
'value': 342000},
'script': '483045022100d936b8baf3b2a85e570a96d73192690b7714604277041a9846454c1a8510688202207aa240aa837ec2fa86e499d36cac42c63c23522a66a3698727ee9abfef0f1b680121020450fbd3d3191b5c632f263676e8a0a4cf286ade84efb3df156426b426660754',
'sequence': 4294967295,
'witness': ''}],
'lock_time': 0,
'out': [{'addr': '1BTa8D9QY38abvApj5yiahh4nJ3XaTfbWA',
'n': 0,
'script': '76a91472b7b93efd311bbce2234913972fe5459d69807d88ac',
'spending_outpoints': [{'n': 9, 'tx_index': 0}],
'spent': True,
'tx_index': 0,
'type': 0,
'value': 133591},
{'addr': '3Nd9T4GqjefS9gzM7SCENGh9tUvUU4Mp8t',
'n': 1,
'script': 'a914e59f42949527e3411b9fbe1cbfba1ec1606d08ff87',
'spending_outpoints': [{'n': 12, 'tx_index': 0}],
'spent': True,
'tx_index': 0,
'type': 0,
'value': 1223069}],
'relayed_by': '0.0.0.0',
'result': -342000,
'size': 666,
'time': 1570559470,
'tx_index': 0,
'ver': 1,
'vin_sz': 4,
'vout_sz': 2,
'weight': 2664}
I appreciate your help. I am struggling in this for quit a time now
Bitcoin transactions have an input/ouput model, I suggest you study up on that: https://en.bitcoin.it/wiki/Transaction, it will answer all of your questions.
I'll explain. Your question to which address did 1ADSb1ZZ9k3NsDf3JTQCQ4mb8bthiAN6NJ pay doesn't make sense because it, along with 3 other addresses paid out to 2 different addresses. In this case, it is usually one address received 1 amount and the second address received change (back to the original owner). To understand what I mean, I'll explain how a transaction is created on Bitcoin.
Scenario
User A wants to send .1 BTC to user B. In order to do that, they must gather up enough previous transaction outputs (where they received Bitcoin) and use them as inputs to the new transaction. So, let's say last week user C sent .05 BTC to user A, and user D sent .1 BTC to user A. You might think user A can just grab the output from user D's transaction and send that to B, but you must include a small fee for the miner in order to get your transaction added to the a block in the blockchain (miners will almost never mine a transaction for free, they get paid the transaction fee, as well as the block reward when they mine a block).
So, in order to cover the fee, let's say it's 0.00003 BTC. User A needs to use both previous outputs so there will be a total of 0.15 BTC sent. Now, you have to spend all of the input, so user A would obviously not want to send that much if they only owe 0.1 BTC so user A will create a transaction which sends 0.1BTC to user A, and 0.04997 BTC (0.05 minus the transaction fee) back to themselves. This is called the change address, and usually is not the same as any address user A has previously used. This is for privacy reasons, so it is harder to tell who received the Bitcoin, and who got the change back if someone was trying to track users spending.

"error": "Prediction failed: unknown error."

I am requesting online prediction for a trained model (model created with linear learner algorithm) and getting "error": "Prediction failed: unknown error."
This is my first ML model in Google AI platform. Model training was successful, training data, validation data and test data all look good in the output folder. But when I try to test the model by passing the input JSON I get this error. I have looked for similar other posts but couldn't find the solution to get a successful prediction.
metadata.json in the artifact folder looks like
{
"feature_columns": {
"col_0": {
"mapping": {
"0": 0,
"1": 1,
"10": 10,
"2": 2,
"3": 3,
"4": 4,
"5": 5,
"6": 6,
"7": 7,
"8": 8,
"9": 9
},
"mode": "0",
"num_category": 11,
"treatment": "identity",
"type": "categorical"
},
"col_1": {
"mapping": {
"0": 0,
"1": 1,
"10": 10,
"2": 2,
"3": 3,
"4": 4,
"5": 5,
"6": 6,
"7": 7,
"8": 8,
"9": 9
},
"mode": "4",
"num_category": 11,
"treatment": "identity",
"type": "categorical"
}
},
"target_algorithm": "TensorFlow",
"target_column": {
"type": "regression"
}
}
The input JSON that I am passing for testing prediction is
{ "instances": [5,5] }
The model is expected to sum the 2 input features and give a result of 10
Can you please advise where the mistake is?
If you are using gcloud to send a file, do:
{"col_0": "5", "col_1": "5" }
If you are sending a bunch of instances through some other client, do:
{
"instances": [
{"col_0": "5", "col_1": "5" },
{"col_0": "3", "col_1": "2" }
]
}
Lak's answer is good and does the job.
Although my input data was different I got the same error, despite successful local predictions. Here are two additional things that helped me.
Run !gcloud ai-platform predict --help to learn more about how your input should be formatted and which flag to use when making the call.
Inspect the model with !saved_model_cli show --dir ${YOUR_LOCAL_MODEL_PATH} --all to check the names of the inputs. Verify that they are in fact (in your case) inputs[col_0] and inputs[col_1].
Using the "TEST & USE" interface you mentioned above (and in this SO answer) allows quicker experimentation.

How can I filter django queryset again to get unique parameters?

Hi I am trying to receive one last message per user. I have filtered out messages but I am getting many messages for one user. How can I get last message of user.
queryset=MessageModel.objects.filter(
Q(sUser=self.request.user) | Q(rUser=self.request.user)
).order_by('-id')
return queryset
I am getting this list from filtering.
[
{
"message": "Hi b do you want to buy? 2",
"sUser": 1,
"rUser": 15,
"sent": true,
"pk": 8,
"user": {
"pk": 15
}
},
{
"message": "a to c",
"sUser": 1,
"rUser": 16,
"sent": true,
"pk": 7,
"user": {
"pk": 16
}
},
{
"message": "No thanks not buying this time",
"sUser": 15,
"rUser": 1,
"sent": false,
"pk": 6,
"user": {
"pk": 15
}
},
{
"message": "c to a",
"sUser": 16,
"rUser": 1,
"sent": false,
"pk": 4,
"user": {
"pk": 16
}
},
{
"message": "Hi b do you want to buy?",
"sUser": 1,
"rUser": 15,
"sent": true,
"pk": 1,
"user": {
"pk": 15
}
}
]
I want to get message with pk 8 and 7 only because it is the last message to user 15 and 16 but I am getting all messages for 15 and 16.
Ok I guess you are going for type like facebook messenger's dashboard. First get the related message of the user
relatedMessage=MessageModel.objects.filter(
Q(sUser=self.request.user) | Q(rUser=self.request.user)
).order_by('-id')
Add the first message to a list
convoList.append(relatedMessage.latest('id')) #since first message is unique
Then find out the friend from each one so that you can distinct who exactly the friend is (either sender or receiver which may be you or friend, since we are filtering message sender or receiver being you or your friend).
friend = message.sUser
if message.sUser==self.request.user:
friend=message.rUser
Great! You found which one your friend is.
Now for each message in relatedMessage check if message of you friend exist in your convoList or not. If it does not exist then add it to the convolist. Finally create serializer and return its data or queryset whichever you prefer.
This is preferred because it just makes one query to the database hence creating calculating part in the server. If you had first got related user from database then gone for again filtering message, it would be much costly due to huge query twice in database.
you have to
queryset=MessageModel.objects.filter(
Q(sUser=self.request.user) | Q(rUser=self.request.user)
).order_by('-id')
if queryset.exists():
return queryset[0]
else:
return None
Hope this will work for you
I'm not sure the Q expressions in your original query match what you asked for, but let's assume you want the most recent received message for every user and that you can depend on the ordering of id such that the higher the id the more recent.
If you are using a database backend that supports DISTINCT ON you can do the following:
most_recent_messages = MessageModel.objects.all().order_by('rUser', '-id').distinct('rUser')
You can add a filter instead of all if you want to filter the queryset further to particular users for example.

Django - serialize to JSON, how to serialize a FK User object

I'm on a page which sends a request to server side for a list of comments of current topic.
like this
localhost:8000/getComments/567 , while 567 is the topic id.
then, in my django view, like this:
def getProjectComments(request, pId):
format = 'json'
mimetype = 'application/javascript' #'application/xml' for 'xml' format
comments = PrjComment.objects.filter(prj=pId)
data = serializers.serialize(format, comments)
return HttpResponse(data,mimetype)
Now , the question is ,
when I try to use jQuery.parseJSON(data) at the browser side.
[
{
"pk": 10,
"model": "app.prjcomment",
"fields":
{
"status": 1,
"time_Commented": "2011-12-11 17:23:56",
"prj": 1,
"content": "my comment 1",
"user": 25
}
},
{
"pk": 9,
"model": "app.prjcomment",
"fields": {
"status": 1,
"time_Commented": "2011-12-11 17:23:51",
"prj": 1,
"content": "comment \u4e00\u4e2a",
"user": 33
}
} ..
I need to use some detail information of user object. (user is a Foreign Key in model PrjComment)
such as user.first_name to display on the comment list.
but here it is only an id for user.("user": 33)
How can I do that? Anyone who can kind help?
Thank you very much
the User is the Django auth_user.
The easy solution would be to specify the values you need:
comments = PrjComment.objects.filter(prj=pId) \
.values('status','time_commented','prj','content','user__id',
'user__username','user__first_name')
Update:
To access your userprofile information use the table name as defined in your AUTH_PROFILE_MODULE setting. In my case the table is called userprofile, and I'd access the data like this:
values('user__userprofile__moreinfo')
where moreinfo is the field you're interested in

Do fixtures with relationships work in app-engine-patch?

I have a fixture with multiple models that I'm using for testing. It
works for the basic models, but fails to create the entities for the
models with relationships. Is this a known limitation of app-engine-patch or am I missing
something? I'm using JSON for the fixture file.
I'm creating the fixture file with 'manage.py dumpdata --format=json >> file.json'
Here are the models involved:
class BibleBook(db.Model):
name = db.StringProperty(required=True)
description = db.TextProperty(required=True)
class Task(db.Model):
name = db.StringProperty(required=True)
description = db.TextProperty(required=True)
energy = db.IntegerProperty(default=1)
focus = db.IntegerProperty(default=0)
empathy = db.IntegerProperty(default=0)
denarii = db.IntegerProperty(default=0)
talents = db.IntegerProperty(default=0)
experience = db.IntegerProperty(default=1)
percent_per_task = db.IntegerProperty(default=5)
bibleBook = db.ReferenceProperty(BibleBook)
level = db.StringProperty(required=True, choices=set(["Catachumen", "Laymen", "Elder"]))
drop_percentage = db.IntegerProperty(default=10)
The json in the fixture file looks like this:
[
{"pk": "ag5sYXctYW5kLWdvc3BlbHIcCxIWbGF3YW5kZ29zcGVsX2JpYmxlYm9vaxgDDA",
"model": "lawandgospel.biblebook",
"fields": {"name": "Luke", "description": "Description"}},
{"pk": "ag5sYXctYW5kLWdvc3BlbHIXCxIRbGF3YW5kZ29zcGVsX3Rhc2sYBQw",
"model": "lawandgospel.task",
"fields": {"empathy": 0, "name": "Study Luke", "level": "Catachumen", "energy": 1,
"focus": 0, "experience": 1, "drop_percentage": 10, "talents": 0,
"bibleBook": "ag5sYXctYW5kLWdvc3BlbHIcCxIWbGF3YW5kZ29zcGVsX2JpYmxlYm9vaxgDDA",
"percent_per_task": 5, "denarii": 0, "description": "The Book of Luke"}}
]
The BibleBook model loads properly, but the Task one does not.
I'm checking this by doing:
books = BibleBook.gql('')
self.assertEquals(books.count(), 1)
tasks = Task.gql('')
self.assertEquals(tasks.count(), 1)
The first test passes, but the second does not.
Thanks,
Brian Yamabe
Thanks, celopes, for asking for the additional code. I decided to play with the json file and fixed the problem by using simple numbers for the pk's. Here's the JSON that fixes the problem for the models and tests I posted:
[
{"pk": "1",
"model": "lawandgospel.biblebook",
"fields": {"name": "Luke", "description": "The Gospel According to St. Luke."}},
{"pk": "2",
"model": "lawandgospel.task",
"fields": {"empathy": 0, "name": "Study the Gospel of Luke", "level": "Catachumen",
"energy": 1, "focus": 0, "experience": 1, "drop_percentage": 10, "talents": 0,
"bibleBook": "1", "percent_per_task": 5, "denarii": 0,
"description": "The Book of Luke"}}
]