I am attempting to use the JavaScript SDK to post a note from my site and then allow a comment to be posted to that note immediately following. I am successful in the first part. Here is a relevant snippet:
alert('posting to path (' + path + ') with params (' + JSON.stringify(params) + ')');
FB.api(path, "post", params, function(response) {
if (response.error) {
alert(response.error.type + ": " + response.error.message);
} else {... do stuff ...}
Notice that I am dumping the variables I am passing for inspection. The results go like this:
When posting the note:
posting to path (/100003217376622/notes) with params ({"access_token":"AAAChRmSu9s8BACFDhWCFnIS8R3OTZCSxZAyL4hLbAQxGUrn0t4ksZC5CS62qlLtAIconOKCreAUpaorzOZCHkxp2DlTfcc2c8vOY5MOLPdHMqdfWMu2V","subject":"Note #1","message":"My note"})
This works fine and the number preceding "/notes" is my profile id.
However, I subsequently try to post a comment to that note and end up with the following.
When posting a comment to that note:
posting to path (/124528970997681/comments) with params ({"access_token":"AAAChRmSu9s8BACFDhWCFnIS8R3OTZCSxZAyL4hLbAQxGUrn0t4ksZC5CS62qlLtAIconOKCreAUpaorzOZCHkxp2DlTfcc2c8vOY5MOLPdHMqdfWMu2V","message":"Comment on Note # 1"})
This results in an error, shown below:
OAuthException: (#200) Cannot access object_id: 124528970997681
The number preceding "/comments" is, in fact, the id of the note, as when I hover over the note link on my wall, I see this URL: http://www.facebook.com/notes/danja-garno/note-1/124528970997681, which does lead me to the note.
Any idea why I would be getting this error?
============================= UPDATE =================================
This morning I posted a link instead of a note and then successfully posted a comment via the same form and code.
Now, I did notice two things that may provide a clue. First, the permalink for the link looks like this:
http://www.facebook.com/permalink.php?story_fbid=285359141511345&id=100003217376622
While the permalink for the note looks like this:
http://www.facebook.com/notes/danja-garno/note-this-note/127723150678263
ALSO, when I directly access these objects via the Graph API URL, I get two different responses.
I got a valid response for the link using this URL https://graph.facebook.com/141246962656776?access_token=AAAChRmSu9s8BAKedPE9DyZB5W0lQYgn71WkFFtR0wIBMHp3Qgr09vmZA7YhvzJbgoigQRHsaqXqOhpmrbzdhWd6QYV8jHvsKjSVMpLZBTD8GI9Lax7p
BUT, when I tried to access the note in the same way using this URL https://graph.facebook.com/124528970997681?access_token=AAAChRmSu9s8BAKedPE9DyZB5W0lQYgn71WkFFtR0wIBMHp3Qgr09vmZA7YhvzJbgoigQRHsaqXqOhpmrbzdhWd6QYV8jHvsKjSVMpLZBTD8GI9Lax7p
All it returned was "false". What's up with that?
I was finally able to get some time to try this out.
I can post a note, then post a comment to that note via the Graph API. I still think it's a timing issue where the graph is sluggish to cross save the note in all the places it needs to (and the graph's database may be the last datastore to be replicated). So I would suggest placing the comment into a hold queue for processing at a later time (maybe give it 1 minute).
Related
I have a rails application in which I would like to generate a url based on a parameter, but for that parameter to be hidden from public view. So essentially working like a POST request but being able to be typed in like a GET request.
For example using a QR reader I could have the address as www.site.com/qr?lot_no=18007 but when a user scans the QR image it only shows www.site.com/qr but displays the results related to lot_no=18007.
Not sure if this is possible or not. But any help would be greatly appreciated.
If all you want to do is to prevent it from showing up in the address bar of the browser, you could use Rails.ajax to make the request dynamically through Javascript.
That will at least hide it from casual inspection, but there is no way to suppress the parameters from the query string on a GET completely, so anyone looking at the Networks tab in the browser (for example) would still see them.
Another alternative would be to encrypt the parameter value.
Maybe the Friendly id gem may be of help here
The following is an example of it's use is
http://example.com/states/washington
instead of:
http://example.com/states/4323454
This is not going to work with a post request as you mention though. It is a way of using a get request that would normally send an id in the params hash to retrieve existing records.
The gem can be found here https://github.com/norman/friendly_id
It is well maintained and up to date
Configure different route for public facing URL, the URL should include encrypted lot id as a path param.
routes.rb
get '/view_lot/:id' => 'QrCodesController#view_lot`, as: :public_view_lot
now in QrCodesController add action view_lot
def view_lot
encrypted_id = params[:id]
id = decrypt_it(encrypted_id)
#lot = Lot.find(id)
render "your_template"
end
in you QR code generation, pass URL to above action with encrypted id like public_view_lot_url(lot_id)
Im trying to figure out what is wrong with my POST data, or Ajax call.
Im using Symfony to create a form, and Ajax to collect and pass the data. Each time I do a POST request I use Firebug's Net panel to look at my POST data. My POST is breaking somewhere, but I can't tell where. The only thing I can see here is when I look at Firebug I am seeing the POST looks different there for each example (the parameters are present in one, and not present in the other), but they should be identical, right? Is this a clue? I don't know how to interpret this, I don't know enough about Firebug, and its obviously not intuitive enough here for this particular issue.
Is this telling me my data isn't encoded correctly?
Here is a non-working example. Notice, "Parameters" is missing. All I see is the "Source" serialized/encoded data:
Now, in the example below, this is what I expect to see. Notice, this one not only contains the "Source" portion and the source data looks identical (but can use a 2nd pair of eyes on this), but there is another section called "Parameters". Why is this elusively missing in the first example and what does the missing "Parameters" mean?
I'm attaching the headers here, too. Maybe this will explain the problem. And posting these here now I do see the different Content-Type, but I think most of my testing was done before I was sending that header.
broken form headers
working form headers
Either something is wrong with the POST data or might I be be missing the Ajax dataType: 'json', or something?
If you have the wrong content type set in the headers, when the data is sent back, and inspected in Firebug, it can't pull them apart as parameters, unless it knows its form encoded data. If the header declares a different type, then if the data is indeed form url encoded, then the browser doesn't parse it as such, therefore can't break it apart into its parameter elements.
So when you make your call, be sure the content type is being sent as 'application/x-www-form-urlencoded' in your Ajax call.
I have been reviewing the documentation located at http://docs.valence.desire2learn.com/res/user.html
I am trying to paginate the number of response i get from /users/.
When i send a get with "/users/" I recieve the expected Json block with all of the users in D2L.
When i try "/users?bookmark=3004" I recieve a 404 error or a path not found error (I have tried many variations on this line of code)
Any asistance would be appreciated.
Note that the route ends with a slash: "/d2l/api/lp/{ver}/users/". This means that your call needs to look something like this:
https://your.lms.domain/d2l/api/lp/1.0/users/?x_b={userId}&x_a={appId}&x_d={userSig}&x_c={appSig}&x_t={timestamp}&bookmark=3004
I'm trying to use Google Federated Login REST API. I can succesfully reach out to the google server and validate a user but I cannot pull parameters from the return url
for example:
http://mysite.com/login/return?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=id_res&openid.op_endpoint=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fud...
All the variables in that return string are not accessible in the params array. I have no idea how to get them out. requst.url, request.query_parameter, and all similar calls do not return the query string.
I think i found the issue. I was using the open-uri library to make the call to google's endpoint url so it may have been stepping outside of the normal rails response/request cycle. I've since used Net::HTTP requests and parse the information from the response.
So I have a very similar issue, where I'm actually building a Rails-based openid provider but being consumed by another Rails app. I basically adapted the code from
The whole URL was:
http://localhost:3000/openid?openid.assoc_handle=%7BHMAC-SHA1%7D%7B5193d33f%7D%7BdBrUwQ%3D%3D%7D&openid.claimed_id=http%3A%2F%2Flocalhost%3A3000%2Fopenid%2Fwarren&openid.identity=http%3A%2F%2Flocalhost%3A3000%2Fopenid%2Fwarren&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.sreg=http%3A%2F%2Fopenid.net%2Fextensions%2Fsreg%2F1.1&openid.realm=http%3A%2F%2Flocalhost&openid.return_to=http%3A%2F%2Flocalhost%2Fsession%3F_method%3Dpost%26return_to%3D&openid.sreg.required=nickname%2Cemail
I had a similar problem where the only parameters being reported were:
{"action"=>"index", "controller"=>"openid"}
So, suspecting that some parameter (maybe a period?) was causing it to hiccup, I went through and deleted them one by one until I found that deleting the following parameter enables the entire thing to go through correctly:
openid.mode=checkid_setup
That left all the remaining parameters correctly being parsed:
{"openid.assoc_handle"=>"{HMAC-SHA1}{5193d33f}{dBrUwQ==}",
"openid.claimed_id"=>"http://localhost:3000/openid/warren",
"openid.identity"=>"http://localhost:3000/openid/warren",
"openid.ns"=>"http://specs.openid.net/auth/2.0",
"openid.ns.sreg"=>"http://openid.net/extensions/sreg/1.1",
"openid.realm"=>"http://localhost",
"openid.return_to"=>"http://localhost/session?_method=post&return_to=",
"openid.sreg.required"=>"nickname,email",
"action"=>"index",
"controller"=>"openid"}
I'm now trying to find why openid.mode causes this issue. It fails even if I change it to openid.mode=5, so it's the key, not the value, causing the problem.
Suspecting the ".mode" part of the string for the trouble (maybe ".mode" is a filetype or something being parsed by the routing?) I am looking towards this post on allowing periods, but it only applies to the value, not the key: rails routing and params with a '.' in them
Will report back if I find more.
Update: I tried, in another Rails app, adding ?openid.mode=0 to the end of a URL -- ".mode" does not result in a parameter being read, but ".modes=" does and so does ".mod=". This confirms that ".mode" is causing a params parsing error.
Update 2: yikes... actually "?a.mode=0" does work. So far, only the complete string "openid.mode" does not work, and this is across various Rails apps. "?openid.mode" with nothing else results in: Parameters: {"openid.mode"=>nil}, but "?openid.mode=" with nothing after the "=" fails to pass any parameters besides action & controller. Very odd.
Update 3: OK, figured it out, I believe -- the params were getting sanitized i.e. deleted by the rack-openid gem, in that gem's path: /lib/openid.rb:168, "sanitize_query_string". This seems to be incompatible with the example I was working with: https://github.com/openid/ruby-openid/tree/master/examples/rails_openid. Going to override that method.
Final update: I replaced this line:
oidreq = server.decode_request(params)
with this line, since we could no longer use the now-empty params hash:
oidreq = server.decode_request(Rack::Utils.parse_query(request.env['ORIGINAL_FULLPATH']))
I have some Javascript that uses Twitter API to get tweets. I parse the data and use jQuery to generate HTML for the DOM.
An aspect of what I want to display is a "View this tweet" link -- yeah, sorta sounds silly, but it allows a user to get a URL for a specific tweet.
I am generating an a tag with an href. The URL is of the form:
http://twitter.com/{twitter-user-id}/status/{tweet-status-id}
where the content in curly braces is actual data extracted from the tweet (no, I am not including the curly braces). For example:
http://twitter.com/Atechtrader/status/57432099984130050
What happens in operation is that this works for some tweets, but not others. For the ones that fails, the Twitter server responds with content that says the requested page does not exist.
Am I doing something wrong?
https://twitter.com/statuses/ID should work.
it will redirect to the needed status.
Unfortunately, all of the answers provided so far rely on an HTTP redirect.
The direct link is of the form: https://twitter.com/i/web/status/{tweet-status-id}
FYI: id_str is the variable you need to call instead of id
id_str should be taken from the tweet object and replaced in
https://twitter.com/statuses/[id_str]
You can use like:
http://twitter.com/itdoesnotmatter/status/[YOURID]
Twitter redirect based on status ID not username.
It works for desktop and mobile.
You can use
'https://www.twitter.com/'+ user.screen_name+'/status/' + id_str
I've been tried it. It's work good:
- Web : https://twitter.com/statuses/ID
- Mobile && Web: https://twitter.com/User_ID/statuses/Tweet_ID
I hope it's helpful for you.