strugglin to create event in javascript as
api.events_create(eventInfo,function(result,ex){
is failing and
catch(FacebookRestClientException){
gives
TypeError: api.events_create is not a function message=api.events_create is not a function
any clue
Some more context would help in debugging this.
You've created the api object, yes? (e.g., var api = FB.Facebook.apiClient;)
I'm having the same problem. If I look at the list of functions attached to FB.Facebook.apiClient using a DOM inspector, events_create() does not exist - even though other methods like events_get() and feed_publishUserAction() are there.
Facebook might have deliberately omitted it.
api.callMethod works - have put a sample call , hope it helps
var eventInfo = {
"name":this.name.value,
"category":"1",
"subcategory":"2",
"host":"My Host",
"location":"JP Nagar",
"city":"Bang",
"start_time":starttime,
"end_time":endtime};
function createEvent(eventinfo) {
try{
//check if user has extended permission to create otherwise prompt him for same
api.users_hasAppPermission('create_event',function(res,ex){
if (res == 0)
FB.Connect.showPermissionDialog("create_event",
function(res,ex){alert("Congratulations events");});
});
dict = {};
dict['event_info'] = eventinfo;
//provide a call back or a sequencer
var ret = api.callMethod(
'events.create',
dict,
function(eventid,ex){
console.log(data);
});
return ret;
}
catch(FacebookRestClientException){
console.log(FacebookRestClientException);
}
return;
}//createEvent routine
Related
In our Android project (download manager) we need to show built-in web browser so we able to catch downloads there with the all data (headers, cookies, post data) so we can handle them properly.
Unfortunately, WebView control we use does not provide any way to access POST data of the requests it makes.
So we use a hacky way to get this data. We inject this javascript code in the each html code the browser loads:
<script language="JavaScript">
HTMLFormElement.prototype._submit = HTMLFormElement.prototype.submit;
HTMLFormElement.prototype.submit = formSubmitMonitor;
window.addEventListener('submit', function(e) {
formSubmitMonitor(e);
}, true);
function formSubmitMonitor(e) {
var frm = e ? e.target : this;
formSubmitMonitor_onsubmit(frm);
frm._submit();
}
function formSubmitMonitor_onsubmit(f) {
var data = "";
for (i = 0; i < f.elements.length; i++) {
var name = f.elements[i].name;
var value = f.elements[i].value;
//var type = f.elements[i].type;
if (name)
{
if (data !== "")
data += '&';
data += encodeURIComponent(name) + '=' + encodeURIComponent(value);
}
}
postDataMonitor.onBeforeSendPostData(
f.attributes['method'] === undefined ? null : f.attributes['method'].nodeValue,
new URL(f.action, document.baseURI).href,
data,
f.attributes['enctype'] === undefined ? null : f.attributes['enctype'].nodeValue);
}
XMLHttpRequest.prototype.origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
// these will be the key to retrieve the payload
this.recordedMethod = method;
this.recordedUrl = url;
this.origOpen(method, url, async, user, password);
};
XMLHttpRequest.prototype.origSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(body) {
if (body)
{
postDataMonitor.onBeforeSendPostData(
this.recordedMethod,
this.recordedUrl,
body,
null);
}
this.origSend(body);
};
const origFetch = window.fetch;
window.fetch = function()
{
postDataMonitor.onBeforeSendPostData(
"POST",
"test",
"TEST",
null);
return origFetch.apply(this, arguments);
}
</script>
Generally, it works fine.
But in Google Mail web interface, it's not working for some unknown reason. E.g. when the user enters his login name and presses Next. I thought it's using Fetch API, so I've added interception for it too. But this did not help. Please note, that we do not need to intercept the user credentials, but we need to be able to intercept all, or nothing. Unfortunately, this is the way the whole system works there...
Addition #1.
I've found another way: don't override shouldInterceptRequest, but override onPageStarted instead and call evaluateJavascript there. That way it works even on Google Mail web site! But why the first method is not working then? We break HTML code somehow?
I've very new to this but essentially I want to create a cleanup function that runs on the server that I can call at any time to reset various things like collections and sessions in one call.
I'm really very new but this is what I have so far. Can someone please help fill me in where I'm going wrong?
I am trying essentially to return two things (and many more in the future) at once. I've done some research on this but it's as far as I can fathom with my skill level at the moment.
It would be much appreciated. Thank you.
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
return Meteor.methods({
//Use this to emplty the form data
cleanUpForms: function() {
var cleanUpPhoneNumbers = orgPhoneNumbers.remove({});
var cleanUpEmailAddresses = orgEmailAddresses.remove({});
return {
cleanUpPhoneNumbers : cleanUpPhoneNumbers;
cleanUpEmailAddresses : cleanUpEmailAddresses;
}
}
});
});
}
By the way, the current error is for line :
cleanUpPhoneNumbers : cleanUpPhoneNumbers;
It states:
Unexpected token
I'm not sure if I'm doing this correctly. I essentially want it to run multiple cleanups in one go, all called from the client to the server with the above method. I hope that makes sense.
The unexpected token is likely for the ; at the end of the line. When building a JSON object, use a comma between the elements...
return {
cleanUpPhoneNumbers : cleanUpPhoneNumbers,
cleanUpEmailAddresses : cleanUpEmailAddresses
}
I think this will return the number of items that where removed. Is that what you are expecting?
Also, just in case you didn't know, you can run 'meteor reset' from the command line to erase ALL collections.
This is the fully adjusted code for any future reference which may help others. Thanks so much to FloatingCoder for the help.
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
return Meteor.methods({
removeAllNewOrgs: function() {
var PhoneNumbers = newOrgPhoneNumbers.remove({});
var Organsations = newOrgansations.remove({});
//If we want to return the data, to get around only being able to return one thing at a time we're return via an array. CLEVS!
return {
PhoneNumbers : PhoneNumbers,
Organsations : Organsations
}
}
});
});
}
Using titanium, does anybody have some simple instructions to get the user's facebook name, once signed into facebook?
you don't need to do any of this, the username is provided in the data response after the login is done.
Look at the appcelerator documentation
I haven't tested the code but you can try this:
var fbuid = Titanium.Facebook.uid; //this would be the logged user's facebook uid
function fQuery() //this function exec the fql query
{
var myQuery = "SELECT name FROM user WHERE uid = "+fbuid;
var data = [];
Titanium.Facebook.request('fql.query', {query: myQuery}, function(x)
{
var results = JSON.parse(x.result);
var username = results[0].name; //user's fb name
});
};
Ah, here is how you do it:
function getFacebookInfo(){
Titanium.Facebook.requestWithGraphPath('me', {}, 'GET', function(e){
if (e.success){
var jsonObject = JSON.parse(e.result);
//do something here with these values. They cannot be passed out of this
//function call... this is an asynchronous call
//that is, do this:
saveToDb(jsonObject.first_name);
} else {
//some sort of error message here i guess
}
});
};
Finally, along with name and username, check out the facebook page for the other variables you can get -
http://developers.facebook.com/docs/reference/api/
FINALLY: be aware that this is a callback, and titanium won't actually wait for this call to finish. That is, any variable declared to hold the results the returned after the requestWithGraphPAth will immediately return, and as a result almost always be empty.
I guess you could make a nifty loop that just... loops until some variable is set to false. And you'd set the variable to false in the callback... but that seems dodgy.
Just make your call back do everything else, that is, save to the db etc etc
If you do go the route of calling Ti.Facebook.authorise() to log in the user, remember to define
Ti.Facebook.addEventListener('login',function(e){
if (e.success){
...
...
} else if (e.error){ } else if (e.cancel) { }
}
before the call. And then, in the success bit, you can make a requestWithGraphPath call and so on. I just save all the details to the database and retrieve them each time after that, works fine for me!
Just started today some dev using Facebook SDK and i can't figure out the logic followed to link the members of the expando object to the fields in the Graph API objects in the example bellow that was taken from facebook C# SDK docs:
public ActionResult RestFacebookPage()
{
FacebookApp app = new FacebookApp();
dynamic parameters = new ExpandoObject();
parameters.page_ids = "85158793417";
parameters.method = "pages.getInfo";
parameters.fields = "name";
dynamic result = app.Api(parameters);
return View("FacebookPage", result);
}
I do understand the page_ids and fields, but not pages.getInfo. It would be great if someone could enlighten me here and tell me where in the documentation i can find a reference that leads me to this....
Thanks a lot!
Not sure I understand what you are asking but there is a pretty decent example about translating php to facebook-c#-sdk over on their project page. Then you can just look up the official facebook developer documentation directly.
If you were asking more off a "how is this implemented" type of question, the best way to do this in my opinion is to break at the line containing app.Api and from there just step through the code. In the Api method there is a check to see if the parameters dictionary contains a key "method". If there is, the sdk figures the call is bound for the old rest api, not the graph api. A few stack frames lower we find the code that makes the url:
protected virtual Uri GetUrl(string name, string path, IDictionary parameters)
{
Contract.Requires(!String.IsNullOrEmpty(name));
Contract.Ensures(Contract.Result() != default(Uri));
if (_domainMaps[name] == null)
{
throw new ArgumentException("Invalid url name.");
}
UriBuilder uri = new UriBuilder(_domainMaps[name]);
if (!String.IsNullOrEmpty(path))
{
if (path[0] == '/')
{
if (path.Length > 1)
{
path = path.Substring(1);
}
else
{
path = string.Empty;
}
}
if (!String.IsNullOrEmpty(path))
{
uri.Path = UriEncoder.EscapeDataString(path);
}
}
if (parameters != null)
{
uri.Query = parameters.ToJsonQueryString();
}
return uri.Uri;
}
You should probably step into this method yourself to see what the variables hold and it should make sense to you. The source is always the best documentation. Hope this helps.
How do I pass the jsonObj from the javascript code in getJson to the java code handleJsonResponse. If my syntax is correct, what do I do with a JavaScriptObject?
I know that the jsonObj contains valid data because alert(jsonObj.ResultSet.totalResultsAvailable) returns a large number :) --- but some how it's not getting passed correctly back into Java.
EDIT: I solved it... by passing in jsonObj.ResultSet.Result to the java function and working on it using a JSONArray.
Thanks.
public native static void getJson(int requestId, String url, MyClass handler) /*-{
alert(url);
var callback = "callback" + requestId;
var script = document.createElement("script");
script.setAttribute("src", url+callback);
script.setAttribute("type", "text/javascript");
window[callback] = function(jsonObj) { // jsonObj DOES contain data
handler.#com.michael.random.client.MyClass::handleJsonResponse(Lcom/google/gwt/core/client/JavaScriptObject;)(jsonObj);
window[callback + "done"] = true;
}
document.body.appendChild(script);
}-*/;
public void handleJsonResponse(JavaScriptObject jso) { // How to utilize JSO
if (jso == null) { // Now the code gets past here
Window.alert("Couldn't retrieve JSON");
return;
}
Window.alert(jso.toSource()); // Alerts 'null'
JSONArray array = new JSONArray(jso);
//Window.alert(""+array.size());
}
}
Not exactly sure how to fix this problem that I had, but I found a workaround. The javascript jsonObj is is multidimensional, and I didn't know how to manipulate the types in the java function. So instead, I passed jsonObj.ResultSet.Result to my function handler, and from there I was able to use get("string") on the JSONArray.
What is toSource() supposed to do? (The documentation I see for it just says "calls toSource".) What about toString()?
If your call to alert(jsonObj.ResultSet.totalResultsAvailable) yields a valid result, that tells me jsonObj is a JavaScript Object, not an Array. Looks to me like the constructor for JSONArray only takes a JS Array (e.g., ["item1", "item2", {"key":"value"}, ...] )