I've try to pass response of facebook api request that I get it via FB JS-SDK into my flash application using external interface but I don't get what response type, it result [object object] when I print it in console but when I try type such as response.name or .id or using scope (some value display correct but some still display [object object]).
So,
First, what data type that returned by fb's response?
How I can pass it into flash apps, what about the type argument that I must set?
Then, which is the effective solution between extract the response each key that store it in an array then pass it into flash then extract again each part or send response object to flash then extract it in flash side?
I'm so confused because when I use JSON.decode method in js, it results nothing (undefined).
I'll appreciate for your attention and solution.
You shouldn't use JSON.decode your facebook data, you already get a JSON object that is ready to work with. Though flash doesn't know what is to be there in your JSON object so there will be no code snippets (consider it as a dynamic object)
For example, when you get your simple information about user*FB.api('/me'...)*, you have a .name property:
...
public function receivedResponce(response:Object):void
{
trace(responce.name);
}
...
You can get any other type of data returned by facebook request, whether it's a friend list or link to the user photo.
There's a lot of information about what fields do facebook requests return, try reading it's API guide
Related
I'm following this tutorial for push notifications, and I'm stuck at the part where it says
To trigger a push message, make a POST request to this URL.
I generated the public and private keys using this site and placed the public key in the applicationServerKey key before calling registration.pushManager.subscribe, and I get a properly formatted JSON response, but I'm unsure of how exactly to generate the Authorization header for use in the POST request to send a notification. Here's what the JSON response from subscribe looks like:
{
"endpoint":"https://fcm.googleapis.com/fcm/send/asdf:qwer",
"expirationTime":null,
"keys":{"p256dh":"key","auth":"auth"}
}
I surmised that the portion after /send should be placed in the to field, but I'm unsure of how to format the Authorization header. Surely I should need to use the private key in some way, but I'm not sure how.
My assumption is that I need to perform some sort of operation on my private key, the p256dh field, and the auth field, and that result will be placed in the key= field in the POST request, but I cannot find the reference for this.
Do you need to create a Firebase project to do this? I'm unsure of whether or not this is the case.
Yes, all access to Firebase products and services requires the creation of a Firebase project. You can't use arbitrary keys to invoke FCM. You must use a service account that's been granted permission to call the API.
Can I send back a function reference or function as such as a response to api call from an express server and the front-end framework is angular js?
I tried to send the response object like: {per: true, listEvnts: events}
where events is a function, but in my client side I only get an object with
one key: {per: true}. The second key is missing.
The desired output would be a response object containing both keys, like: {per: true, listEvents: events}.
No, you cannot send functions over HTTP. Functions are specific to the program they are a part of. You cannot send that over a network. You can't even serialise the function into JSON, since JSON doesn't specify a "function" type.
You'd have to send the source code of the function as string and then eval that source code into an actual function on the client, but that's a bad idea. You don't necessarily know the client, and any code you send isn't guaranteed to be executable on that client in that specific context.
Send data, not code.
No this is not possible. If you want to call function from client to server you can create RPC kind of structure. Please provide the details what exactly your requirement here, So can help you better.
{per: true, listEvnts: events} is simple json string, misssing of "events" may have some other reason more detail about your requirement and current object will help to understand query.
I am using MS Web API 2 to receive calls from our web page using ajax.
Then I have 2 classes: subscriber and externalSubscriber. Subscriber contains very basic data like a name and id. External subscriber inherits from subscriber and adds basic data like address and email. I have one api method to edit the data of a subscriber defined like this:
public IHttpActionResult PutSubscriber(int id, Subscriber subscriber)
In our page I create a json string using the data provided which leads to it ether being a external or a normal subscriber.
I am able to post to this function using both but with an externalSubscriber object the added data gets lost and trying to cast from subscriber leads to an error.
my question is if anyone has any experience with this issue and if there is another way to fix this besides creating a specific function for putting a external subscriber.
I have got it to work by using the information provided on the following pages:
http://www.newtonsoft.com/json/help/html/SerializeTypeNameHandling.htm
Polymorphism in Web API: Single endpoint possible?
First I set the json setting:
jsonsettings.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto;
then setting the type of the json object before sending with ajax using
jsonObject { '$type' : .Models.ExternalSubscriber, solution.project', ....}
after this I am able to cast the incoming Subscriber to an ExternalSubscriber and access its properties.
I want to override the collection for development purpose (return fake json results from a JSON var or JSON file). But I got error doing below with url
http://jsfiddle.net/qhoc/uZhM8/
GET http://fiddle.jshell.net/_display/[object%20Object],[object%20Object] 404 (NOT FOUND)
However, if I use parse, it seems the parse got executed right after initialize because of both my console.log results show the same thing
http://jsfiddle.net/qhoc/uZhM8/1/
So how to override the url so that fetch can add another JSON at some point (in separate function)?
The url of a collection is supposed to return a URL which will be used with $.ajax to talk to the server:
url collection.url or collection.url()
Set the url property (or function) on a collection to reference its location on the server. Models within the collection will use url to construct URLs of their own.
Your url method is returning an array and Backbone is treating that like a URL string, hence the odd looking URL that produces your 404.
You have some options:
Use a URL that uses jsfiddle's AJAX stubbing tools to produce the necessary JSON.
Override sync to use some inlined JSON instead of a $.ajax call.
Override fetch to use some inlined JSON instead of calling sync.
If you're only concerned about fetching data then all three should work, if you need to simulate saves or deletes, then you'll probably end up overriding sync.
I want to create a parser for login page. I have a url that gives response in json. When not logged in it gives response as :
{"status":0,"msg":"Email is Wrong!"}
and when loggged in it gives :
{"status":1,"msg":"Session is active","session_id":"lp47ngp9hlqtrkunjirqa7ijg5","user_id":"13"}
I have no idea how to start this. Please help...
Thanks in advance!
Not sure if I'm understanding a real question here, but as I understand it, try using jquery ajax to retrieve your json from the url. In the call to ajax, there'll be a parameter called success, that takes a function with one argument. That argument will be the data retrieved from the url. Simply do obj = eval(data), and your data will be parsed and you can access the status as obj.status.
Using plain javascript you can use JSON.parse to convert the JSON string to a Javascript Object.
Something like:
var response = JSON.parse([yourJsonString]);
if (response.session_id) {
// logged in, proceed
} else {
// not logged in, act accordingly
}
JSON.parse is available in modern browsers. For older browsers you need to include a JSON parser like this one (use json2.js)
If you use jquery and jquery.ajax/jquery.get, etc., you will receive a response in the form of a javascript object that you may use to react accordingly.
Jquery is an excellent javascript library very very widely used. It's kind of a defacto standard.
Just google it and you will find a lot of information, tutorials, books. In Stack Overflow you will find a lot of material on this topic.
You can use the jQuery parseJSON method to parse the JSON string into Javascript object
http://api.jquery.com/jQuery.parseJSON/