Message Online Friends - facebook-graph-api

FQL Query
SELECT name, online_presence IN ('active', 'idle') FROM user WHERE online_presence IN ('active', 'idle') AND uid in(SELECT uid2 from friend where uid1= me())
By This Query I am getting friends
Please Anyone Tell Me how can I message these online friends.

Method 1:
Assume:
Your app id is "87741124305"
"4" is one of your friend uid get from FQL query:
SELECT uid, name, online_presence FROM user WHERE online_presence IN
('active', 'idle') AND uid in(SELECT uid2 from friend where uid1=
me())
you want to share a link "https://www.youtube.com/watch?v=VM56POaEEX4"
https://www.youtube.com/facebook_redirect is your app CANVAS_URL
The full link would be:
https://www.facebook.com/dialog/send?app_id=87741124305&to=4&link=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DVM56POaEEX4%26feature%3Dshare&redirect_uri=https%3A%2F%2Fwww.youtube.com%2Ffacebook_redirect
Method 2:
Send email to him.The email address is in the form USERNAME#facebook.com You can get the USERNAME via FQL query:
SELECT uid, username, online_presence FROM user WHERE online_presence
IN ('active', 'idle') AND uid in(SELECT uid2 from friend where uid1=
me())
Please note that, some user doesn't have username. Also, you can't send empty body message.
Method 3:
You may refer to https://developers.facebook.com/docs/chat/ for Jabber/XMPP service.

Related

how to store commaseperated values in one column ,if user selected morethan one choice from form

I have "user" Model
username email phonenumber
I want to access all "user" model emails in other model "B" and make user to select more than one email and store it has commaseperatedvalues
"B" colums are
organization Designation share_knowledge_with
abc manager (here all emails which user selected
to be stored with commaseperated)
I tried like this but not working:
MODEL
class B(models.Model):
organization=models.CharField(max_length=200,blank=False,null=True)
emails_for_help = models.TextField(null=True,help_text="select with whom
you want to share knowledge")
form
class Bform(ModelForm):
emails_for_help=forms.ModelMultipleChoiceField(queryset=User.objects.all(),
widget=forms.CheckboxSelectMultiple)
class Meta:
model=B
fields=["organization","emails_for_help"]
I tried like this but it is taking null value in "emails_for_help"
emails_for_help = models.TextField(null=True,help_text="select with whom
you want to share knowledge")
Change this to
emails_for_help = models.TextField(null=False,help_text="select with whom
you want to share knowledge")
to refuse null values. It will throw an exception you will have to handle, and in that exception you could display a message to the user that no selections aren't permitted.

Django ORM Confusion with Query

I have customer Model
Name, Email, Phone, State
example
A, Aemail, Apohone, Astate
A, Bemail, Apohone, Astate
A, Cemail, Apohone, Astate
Means one customer with multiple emails.
Here what i want to get out of the query.
[{A, Aphone, Astate, [Aemail, Bemail, Cemail]},
{....},
]
Tried
Customers.objects.filter(**params).values_list('phone', 'name').distinct()
Thougts?
The schema you describe is sub-optimal. Using this schema will result in consistency issues when only some of the user's data will be updated/deleted.
If you want the Customer to have multiple emails if would be wiser to create a separate Email model or use array field.
class Customer(models.Model):
name = models.CharField(max_length=50)
class CustomerEmail(models.Model):
customer = models.ForeignKey(Customer, related_name='emails')
email = models.EmailField()
Now it becomes easy make the query you want.
customers = Customer.objects.select_related('emails')
And get their emails:
for email in customers.emails:
print(email.email)

Accessing rowset after committing a transaction

I have a problem with django and msssql (stored procedure):
com_error at /add_client/
(-2147352567, 'Ocurri\xf3 una excepci\xf3n.', (0, u'Microsoft SQL Server Native
Client 10.0', u'The object is in a zombie state. An object may enter a zombie
state when either ITransaction::Commit or ITransaction::Abort is called, or when a
storage object was created and not yet released.', None, 0, -2147418113), None)
Stored Procedure:
ALTER PROCEDURE [dbo].[InsertPerson](
#first_name nvarchar(80),
#last_name nvarchar(80),
#dni nvarchar(10),
#sex nvarchar(2),
#phone_number nvarchar(10),
#cellular_number nvarchar(9),
#email nvarchar(50),
#bank_account nvarchar(25),
#department nvarchar(50),
#province nvarchar(50),
#district nvarchar(50),
#address nvarchar(50),
#description nvarchar(128),
#is_active nvarchar(2),
#creation_time bigint)
AS
SET NOCOUNT ON
INSERT INTO persons (first_name, last_name, dni, sex, phone_number, cellular_number,
email, bank_account, department, province, district, address, description, is_active,
creation_time)
VALUES(#first_name, #last_name, #dni, #sex, #phone_number, #cellular_number, #email,
#bank_account, #department, #province, #district, #address, #description, #is_active,
#creation_time)
SELECT ##IDENTITY AS person_id
SET NOCOUNT OFF
This procedure is working perfect, but the problem is when Accessing rowset after committing a transaction (get the insert id).
My view in Django is:
from django.db import transaction
...
#transaction.commit_manually
def add_client(request):
...
...
...
description = request.POST.get('description', '')
is_active = request.POST.get('is_active', '')
cursor = connection.cursor()
cursor.callproc("InsertPerson", (first_name, last_name, dni, sex, phone_number, cellular_number, email, bank_account, department, province, district, address, description,
is_active, creation_time))
connection.commit()
row = cursor.fetchone()
return HttpResponse(json.dumps({"mensaje": row.person_id}), content_type='application/json')

Run multi-query fql in graph api explorer

Trying to run this in the Graph API Explorer:
"query1":"SELECT uid, message FROM status where uid in (SELECT uid2 from friend where uid1 = me())"
"query2":"SELECT name from user where uid in (select uid from #query1)"
But all I get is:
{ "data": [ ] }
I'm completely new into this. What am I doing wrong?
You most likely have a formatting issue
fql?q={"query1":"SELECT uid, message FROM status where uid in (SELECT uid2 from friend where uid1 = me())", "query2":"SELECT name from user where uid in (select uid from #query1)"}
Works fine for me.

Select field of field using facebook graph api

does facebook support field of filed for graph api?
For example,
https://graph.facebook.com/[uid]/friends/?fields=events
will give all friends and their events.
Can I also control which field i want in the events by doing something like
<https://graph.facebook.com/[uid]/friends/?fields=events,events__updated_time>
Thanks
You can't do this directly through the Graph API, however the best thing to do with more complex queries is to look into FQL. In your specific example, you can do something like this:
SELECT eid, update_time FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()))
You can run this against the Graph API by doing:
https://graph.facebook.com/fql?q=SELECT eid, update_time FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()))
Test this using the Graph API Explorer