I'm working in Koala with Facebook's Graph API 2.0. Now when you call user_friends using
<% #friends = #graph.get_connections("me", "friends") %>
You should get an object that contains something like the following:
{
"data": [
{
"name": "Friend 1",
"id": "xxxxx"
},
{
"name": "Friend 2",
"id": "xxxx"
},
],
"paging": {
"next": "https://graph.facebook.com/v2.1/...."
},
"summary": {
"total_count": number of friends
}
}
My question is how do I pull the information from summary. I tried printing this in my ruby app but I only saw the following:
[]
Does that mean the return was nil? I tried to call #friends.summary, but that didn't work
Thoughts?
https://developers.facebook.com/docs/apps/changelog
The list of friends returned via the /me/friends endpoint is now limited to the list of friends that have authorized your app.
Also make sure you authorized yourself with the user_friends permission, of course.
Related
On my application, I would like to add a post and user in tandem using jsonapi:resources. A user can be created already. And a post can be created already if someone is signed in. However for this special scenario I would like a user to be able to submit their first post while creating their account. Here is the payload that would be submitted.
{
"data":{
"user":{
"attributes":{
"name": "blah blah",
"age": 20,
"address": "mickey mouse street"
}
},
"relationships": {
"post": {
"content": "this is a new post",
"type": "blog"
}
}
}
}
Is this at all possible? If so in which resource file would I create them both? Would it be the resource file for posts or for users? Or would it be best practice to create the user first and then once the user has been created make a separate call to create the post? Thanks!
Setup:
Rails 5, using ActiveModel::Serializer and Kaminari
Sample code:
def index
#catalogs = Catalog.page(params[:page])
render json: #catalogs, adapter: :json_api
end
Problem:
When params[:page] is nil, my result is as expected:
{
"data": [
{
"id": "a020ab21-9028-4bfd-8f9c-1b735ed4734b",
"type": "catalogs",
"attributes": {
"name": "First",
"locale": "en"
}
}
],
"links": {
"self": "http://localhost:3000/v1/catalogs?page%5Bnumber%5D=1&page%5Bsize%5D=1",
"next": "http://localhost:3000/v1/catalogs?page%5Bnumber%5D=2&page%5Bsize%5D=1",
"last": "http://localhost:3000/v1/catalogs?page%5Bnumber%5D=3&page%5Bsize%5D=1"
}
}
However, when I make a Postman call to the "next" URL (http://localhost:3000/v1/catalogs?page%5Bnumber%5D=2&page%5Bsize%5D=1),
I get:
Started GET "/v1/catalogs" for 172.18.0.1 at 2017-09-08 15:27:04 +0000
undefined method `to_i' for #<ActionController::Parameters:0x0000c68977f718>
Did you mean? to_s
to_h
Is there something different that has to be done with Rails 5 params to get pagination for ActiveModel::Serializers to work?
It appears params[:page] doesn't hold the page number, but a "hash": { number: 1, size: 1 }. That said, you want to use the page number as the argument to page:
def page_params
params.fetch :page, {}
end
#catalogs = Catalog.page(page_params[:number])
Maybe even call .per(page_params[:size]) too, to let the API change that as well.
Solution:
I encountered nested pagination params problematic in some cases. You could use params page and per_page instead of page[number] and page[size]. Solution for will_paginate is in this comment on GitHub issue. Solution is probably also for kaminari, because its the issue of serialization gem, not pagination gem.
Explanation:
As Leonel explained, link that you are clicking:
localhost:3000/v1/catalogs?page%5Bnumber%5D=2
is the same as:
localhost:3000/v1/catalogs?page[number]=2
so your code should access these params like:
params[:page][:number]
not:
params[:page]
Solution from above, using ActiveModel::Serializers will create links like this:
localhost:3000/v1/catalogs?page=2&per_page=50
So you can access pagination params like you want in your controller:
Catalog.page(params[:page]) # page number
Catalog.per(params[:per_page]) # page size
I'm trying to implement Document signing on my rails app.
I have a template which is sent to many users.
So i have made a custom tag with label Member and i want to fill it with a custom text say 'abc' through my app.
Here is my code which i tried so far. The member part still looks blank. Other fields like name, signature and date are working properly.
client = DocusignRest::Client.new
#envelope_response = client.create_envelope_from_template(
status: 'sent',
email: {
subject: "The test email subject envelope 7",
body: "Envelope body content here"
},
template_id: template_id,
signers: [
{
name: 'Name',
email: 'sample_email#gmail.com',
role_name: 'Expert',
tabs: {
text_tabs: [
{
tab_label: 'Member',
value: 'abc'
}
]
}
}
]
)
I dont know where i went wrong. Please help
it seems the 'text_tabs' should not be embedded inside a 'tabs'. instead, pass the 'text_tabs' directly within a signer. also, instead of 'tab_label', try just using 'label'.
I am trying to test the docusign_rest gem for possible integration into my rails app. I have set up the gem and configured it with my username, password, and integrator key. I have set the version of the api to 'v2' and checked all the of the names of both the signers and the tab fields multiple times. Here is the code I am using to make the request:
response = c.create_envelope_from_template(
status: 'sent',
email: {
subject: "Test email subject",
body: "Test email body",
},
template_id: template["templateId"],
signers: [
{
embedded: false,
name: "Name",
email: 'example#gmail.com',
role_name: "Signer1",
tabs: {
textTabs: [
{
tabLabel: "\\*address",
value: "123 Example St.",
locked: true
}
]
}
}
]
)
The request gets sent and the envelope gets sent but the 'address' field is not populated. Is there anything I am doing obviously wrong?
Thanks in advance.
Try changing the signers node in you request body to templateRoles. When you use templates in DocuSign instead of specifying the signers and their types and tabs, you assign them to existing template roles that are configured in the template. That's why no signer types should be specified in this call, just the template roles that each recipient will get matched to, and the values of any tabs you want to populate.
I've never used Ruby before so there might be some formatting or syntax issues I'm missing here, and I also have never seen the ruby gem you're referring to so not sure how stable or correct that code is. But basically this is what I think you need to do...
Right now you have:
status: 'sent',
email: {
subject: "Test email subject",
body: "Test email body",
},
template_id: template["templateId"],
signers: [
{
...
Try changing signers to templateRoles, like so:
status: 'sent',
email: {
subject: "Test email subject",
body: "Test email body",
},
template_id: template["templateId"],
templateRoles: [
{
...
The resulting http request body that you need to construct should look something like the following (in JSON format):
{
"emailSubject": "DocuSign API - Signature Request from Template",
"templateId": "ABCD1234",
"templateRoles": [
{
"email": "firstperson#email.com",
"name": "John Doe",
"roleName": "Template Role Name goes here",
"tabs": [
{
"textTabs": [
{
"tabLabel": "\\*address",
"value": "432 Sorrento Dr.",
"locked": "true"
}
]
}
]
}
],
"status": "sent"
}
Lastly, the DocuSign API Walkthrough for requesting a signature from a template is a great resource for sending from a template so this might help too. There's sample code for making this api call in 6 different languages (unfortunately Ruby is not one of them):
http://iodocs.docusign.com/APIWalkthrough/requestSignatureFromTemplate
Finally figured it out myself by modifying the gem to inspect the request. With the docusign_rest gem, the documentation on the github page is incorrect. The tabs dictionary should not be there and the items in this specific request should be underscore separated instead of camel case. Therefore, the actual request would look something like:
response = c.create_envelope_from_template(
status: 'sent',
email: {
subject: 'Test email subject',
body: 'Test email body',
},
template_id: template["templateId"],
signers: [
{
embedded: false,
name: 'Name',
email: 'example#gmail.com',
role_name: 'Signer1',
text_tabs: [
{
label: 'Address',
name: 'Address',
value: '123 Example Street.',
}
]
}
]
)
This request will allow you with the gem and v2 of the api to create an envelope from a template and prepopulate any fields. All other field types go the same way as the text_tabs array.
I'm doing it on ios. When I get a user's info(gendar,locale,etc), such as Bill Gates(216311481960), it will return error. Maybe because these info are not public. If I just get name,link, picture, that will be OK. But how can I handle this kind of error. How can I know which info can be retrieved?
Thanks.
Without a user access token, pubic info can be grabbed this way: http://graph.facebook.com/216311481960
{
"id": "216311481960",
"name": "Bill Gates",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/276582_216311481960_498814368_s.jpg",
"link": "http://www.facebook.com/BillGates",
"likes": 1216122,
"category": "Public figure",
"is_published": true,
"website": "www.thegatesnotes.com www.gatesfoundation.org",
"username": "BillGates",
"talking_about_count": 25035
}
As you can see this doesn't appear to be user information, but rather page information.
For user information, you need to use a Facebook user id. Zuck's is 4...so do: http://graph.facebook.com/4
{
"id": "4",
"name": "Mark Zuckerberg",
"first_name": "Mark",
"last_name": "Zuckerberg",
"link": "http://www.facebook.com/zuck",
"username": "zuck",
"gender": "male",
"locale": "en_US"
}
Notice how it has both first_name and last_name, while the "Bill Gates" one you have as an example is clearly not a "user" but a page.
With a valid user access token, all shared information can be grabbed this way:
http://graph.facebook.com/me?access_token=ValidUserAccessToken