Friday, 15 July 2011

android - Unable to get facebook incoming requests -



android - Unable to get facebook incoming requests -

i trying implement send info , take info in facebook android game app.i next https://developers.facebook.com/docs/android/send-requests/#notifications tutorial that. able send request unable take info @ recipient side .

my intenturi returning null every time that's unable requestids.

my code getting info @ recipient side:

intenturi = mainactivity.this.getintent().getdata(); if (intenturi != null) { string requestidparam = intenturi.getqueryparameter("request_ids"); if (requestidparam != null) { string array[] = requestidparam.split(","); requestid = array[0]; log.i("request id: ", "request id: " + requestid); }else{ log.i("request id: ", "null" ); } } else { log.i("intenturi", "null"); //**always printing part** }

onsessionstatechange() method calling requestdata method

private void onsessionstatechange(session session, sessionstate state,exception exception) { if (state.isopened() && requestid != null) { getrequestdata(requestid); requestid = null; } }

i sending request using next method :

private void sendrequestdialog() { bundle params = new bundle(); params.putstring("message", "learn how create android apps social"); params.putstring("data", "{\"badge_of_awesomeness\":\"1\"," + "\"social_karma\":\"5\"}"); webdialog requestsdialog = (new webdialog.requestsdialogbuilder( mainactivity.this, session.getactivesession(), params)) .setoncompletelistener(new oncompletelistener() { @override public void oncomplete(bundle values, facebookexception error) { if (error != null) { if (error instanceof facebookoperationcanceledexception) { toast.maketext(mainactivity.this, "request cancelled", toast.length_short) .show(); } else { toast.maketext(mainactivity.this, "network error", toast.length_short) .show(); } } else { final string requestid = values .getstring("request"); if (requestid != null) { toast.maketext(mainactivity.this, "request sent", toast.length_short) .show(); } else { toast.maketext(mainactivity.this, "request cancelled", toast.length_short) .show(); } } } }).build(); requestsdialog.show(); }

code accepting request below:

private void getrequestdata(final string inrequestid) { // create new request http // request id graph path. request request = new request(session.getactivesession(), inrequestid, null, httpmethod.get, new request.callback() { @override public void oncompleted(response response) { // process returned response graphobject graphobject = response.getgraphobject(); facebookrequesterror error = response.geterror(); // default message string message = "incoming request"; if (graphobject != null) { // check if there info if (graphobject.getproperty("data") != null) { seek { // data, parse info // key/value info jsonobject dataobject = new jsonobject( (string) graphobject .getproperty("data")); // value key - // badge_of_awesomeness string badge = dataobject .getstring("badge_of_awesomeness"); // value key - social_karma string karma = dataobject .getstring("social_karma"); // sender's name jsonobject fromobject = (jsonobject) graphobject .getproperty("from"); string sender = fromobject .getstring("name"); string title = sender + " sent gift"; // create text alert based on // sender // , info message = title + "\n\n" + "badge: " + badge + " karma: " + karma; } grab (jsonexception e) { message = "error getting request info"; } } else if (error != null) { message = "error getting request info"; } } toast.maketext(mainactivity.this, message, toast.length_long).show(); deleterequest(inrequestid); } }); // execute request asynchronously. request.executebatchasync(request); }

note : using simple activity , not using fragments

the method getintent() returns intent started activity. can seek overriding activity method

protected void onnewintent(intent intent)

and phone call

setintent(intent intent)

from there.

you can seek requesting info using:

intent intent = mainactivity.this.getintent(); bundle bundle = intent.getextras(); intenturi = (uri)bundle.get(intent.extra_text);

aside that, , how calling intent.putextra("request_ids", data) ?

not sure if i've understood problem,

anyways, wish luck.

edit:

you may want utilize intent.extra_stream instead of intent.extra_text, depending on way store data

android facebook facebook-graph-api facebook-apps facebook-requests

No comments:

Post a Comment