Has anyone been able to customize a Facebook feed post by using parameters like from, to, actions, etc, as documented here:
http://developers.facebook.com/docs/reference/api/post/
For example HTTP POSTing this string:
message=mymessage&access_token=mytokenstring
to
https://graph.facebook.com/123456/feed works fine and posts to your feed. Similarly parameters like picture, description, etc all work too.
But I can't get the more complicated parameters to work. Does anyone know the proper formatting? My guess below, and similar combinations, doesn't work at the moment:
message=mymessage&access_token=mytokenstring&from={"name":"Bob", "id":"123456"}
thanks for any help!
This is how I used PHP to implement actions:
$attachment = array
(
'access_token'=>$facebook->getAccessToken(),
'message' => 'I\'ve been testing my IQ!',
'name' => 'IC-YOUR-IQ',
'caption' => 'This is my result:',
'link' => 'http://apps.facebook.com/icyouriq/',
'actions' => array('name'=>'Sweet FA','link'=>'http://www.facebookanswers.co.uk'),
'description' => $cmsg,
'picture' => 'http://www.facebookanswers.co.uk/img/misc/iq.jpg'
);
The key line is the "actions" element. From my experiments I was only ever able to get one action to appear. But hopefully you get the picture.
The full article I wrote on this can be found here:
http://facebookanswers.co.uk/?p=270
hmm that makes sense but doesn't appear to work. In the end they are expecting json I guess. Also I don't think 'from' or 'to' tags are supported when creating a post, but actions are. This string worked:
&actions=[{"name":"My%20Link","link":"http%3A%2F%2Fmysite.com%2Fdownload.html"}]
close, but it should be:
from[name]="Bob"&from[id]=123456
so mainKey[subKey]=value&mainKey[subKey2]=value2
In javascript you can use the function ui , with the feed method, There is an example here:
http://aplicacionesfacebookparadummies.blogspot.com/2011/09/compartir-en-aplicaciones-facebook.html
fields=posts.fields(message,actions)
Related
there is a website called https://www.guidgenerator.com/online-guid-generator.aspx which generates a global unique identifier. I'm trying to use perl's Mechanize to post to the site to pull that guid. I realize that this is based on javascript but was wondering if I could issue the proper post to pull the number. I trace it from my browser and I've got the headers all in the request but the returned html doesn't contain the guid.
This is from a successful run:
<textarea name="txtResults" rows="2" cols="20" id="txtResults" style="font-family:Courier New,Courier,monospace;font-size:Larger;font-weight:bold;height:152px;width:421px;">qk5DF22bhkm4C2AwZ5OcZw==</textarea>
and this is from my script:
<textarea name="txtResults" rows="2" cols="20" id="txtResults" style="font-family:Courier New,Courier,monospace;font-size:Larger;font-weight:bold;height:152px;width:421px;"></textarea>
This is the form within the page:
In my script I dump out the form and the input fields required with the following:
my #forms = $mech->forms;
foreach my $form (#forms) {
my #inputfields = $form->param;
print Dumper \#inputfields;
}
resulting in
$VAR1 = [
'__EVENTTARGET',
'__EVENTARGUMENT',
'__LASTFOCUS',
'__VIEWSTATE',
'__VIEWSTATEGENERATOR',
'__EVENTVALIDATION',
'txtCount',
'chkUppercase',
'chkBrackets',
'chkHypens',
'chkBase64',
'chkRFC7515',
'chkURL',
'LocalTimestampValue',
'btnGenerate',
'txtResults'
];
and this is the post
my $mainpage = "https://www.guidgenerator.com/online-guid-generator.aspx";
$mech->post( "$mainpage",
fields => {
'txtCount' => "1",
'chkBase64' => "on",
'LocalTimestampValue' => "Date%28%29.getTime%28%29",
'btnGenerate' => "Generate+some+GUIDs%21",
'txtResults' => "",
'__EVENTTARGET' => 'on',
'__EVENTARGUMENT', => 'on',
'__LASTFOCUS', => 'on',
'__VIEWSTATEGENERATOR' => "247C709F",
'__VIEWSTATE' => 'on',
'__EVENTVALIDATION' => 'on',
'chkUppercase' => 'off',
'chkBrackets' => 'off',
'chkHypens' => 'off',
'chkRFC7515' => 'off',
'chkURL' => 'off',
},
);
When I do the trace on the website I get the headers but there is another tab called Payload. That contains most of the fields listed above. I try to input these fields into the POST but not sure if I should be doing this differently or it doesn't matter because its javascript?
I know this is a lot of information. I'm not even sure that perl's mechanize can pull this information. Any help would be appreciated. Please let me know any other data you want me to post here.
You can use Mech's built-in stuff to do this. There is no need to submit any extra fields or headers.
use strict;
use warnings;
use feature 'say';
use WWW::Mechanize;
my $mech = WWW::Mechanize->new;
$mech->get('https://www.guidgenerator.com/online-guid-generator.aspx');
$mech->field( txtCount => 10 );
$mech->click;
say $mech->value('txtResults');
This will output something like:
$ perl mech.pl
211b3cad1665483ca303360bdbda0c61
ecc3348d83cb4bb5bdcb11c6148c5ae1
0a3f2fe5748946a1888a4a5bde8ef2e6
acb26deb9fda4411aa64638cdd1ec5f1
2afe609c355b4a10b6a0ae8c74d3aef1
30fd89ab170147cfb24f131346a203e3
2301d258e1d045aa8f0682f2ea14464c
f064507ca3e14a4eb860b0a30ba096ed
9a42b15d5c79420c921dcc07c306459b
5bea2e345f75453caaf795681963866a
The crux here was that you cannot use $mech->submit as that wouldn't submit the value of the submit button. That's a bit annoying. So instead, you have to use $mech->click, which pretends the default form's default submit button was clicked, hence submitting that value as well. That's just how buttons work on forms, and in this case the backend checks the value to see which one was clicked.
You can then use $mech->value to get the field value out. You'd probably want to split it to process it further.
The JavaScript in this page is actually completely irrelevant to the functionality. All it does is save and restore the settings you've chosen in a cookie, so that when you come back the same checkboxes will be ticked. That's nice, but nowadays probably better done with local storage on the frontend side. However you don't have to deal with the JS at all to crawl this page. The main functionality is backend side.
You might also be interested in $mech->dump_forms, which is a nice debugging aid that prints out all the forms with fields and values. Another good debugging aid when working with Mech (or any LWP based class) is LWP::ConsoleLogger::Everywhere. That's what I used to compare my program's request with my browser's one to find the missing button form field.
Disclaimer: I am a maintainer of WWW::Mechanize and I wrote LWP::ConsoleLogger::Everywhere.
Codebird.js is not working when I try to return a list of n number of tweets by adding to my params object.
It works when I include just the property screen_name to get a single tweet but when I add count in, as below, the response I get is still for only one tweet
params = {
"screen_name": screenName,
"count": "3"
};
I can't seem to find any codebird.js documentation besides the README.MD on the main github page.
Is my syntax correct? Am I approaching this the correct way by adding to params
Solved it. Turns out I was using the wrong api endpoint and should have been using statuses/user_timeline.
Note: Check this part of the docs to see how to map this endpoint's string to the right format https://github.com/jublonet/codebird-js#mapping-api-methods-to-codebird-function-calls
I found several sources discussing this problem, (this one seems the simplest but it is for PHP). I will be using an existing search form and I created AutocompleteResponse handler to handle the request. I don't understand from the documentation if it is required that the data sent will be in json format or an array of string is ok. I am not sure about what information to send either. I created a new model with search history
class Search(db.Model):
owner = db.UserProperty()
date= db.DateTimeProperty(auto_now_add=True)
query = db.StringListProperty()
and I want to send the relevant query suggestions to autocomplete. Any help to examples whether in documentation or otherwise is welcome. Thanks.
Update
I put this just before the closing </body>
<script>
$('#search_form').autocomplete({
source: "http://ting-1.appspot.com/autocomp",
minLength: 2});
</script>
in my Autocomp handler I put
data = json.dumps("abc, def")
I naively think that data will be passed to jquery autocomplete plug in. But nothing is happenning. What am I doing wrong?
Just tried this and it worked:
data = ['cat','dog','bird', 'wolf']
data = json.dumps(data)
self.response.out.write(data)
I'm puzzling on the following problem: in my web app users can select their language from a dropdown box. Upon selection, a piece of Javascript takes the current url, replaces the old locale substring in it with the new locale string and sets the window.location to the new url. That works great as long as the URL the result of a GET request.
My problem occurs when the user posts a form and it returns a validation error. The url is now a POST url, that (in my case) does not work with a GET request. Hence, if the user now decides to switch language, an invalid GET request will be sent to the server.
Any ideas how to solve this?
To be a little more specific: I'm running into this problem in Rails 3.0.9 on the registration form of Devise (1.4.2)
I often write my own routes to avoid the exact problem you are describing. I think it's a big flaw in Rails routing.
You may be able to change the Devise routes, and the rest of your resource routes, so that your GET and POST URLs look identical. Here's an example of what I mean.
scope '/posts' do
get '/:id/edit' => "posts#edit", :as => "edit_posts"
post '/:id/edit' => "posts#update", :as => "update_posts"
end
It's a bit more work doing things that way, though.
You could always disable the locale select for the pages where you have problems.
You could check with javascript if there is a .fieldWithError classed element on the page. If so, you can be sure that the last request was POST. In that case, you would have to change the 'action' attribute for the form (change the locale) and submit it again.
You can not access the HTTP method of the current response with javascript.
#WizardofOgz thanks for putting me on the right track. I'm adding this answer, so that I can paste in some code, which I can't in a comment, but I'll accept your answer.
I found this related post specifically for Devise. I've tested it on the password reset routes and this seems to work fine (although I guess this isn't complete yet):
devise_for :user, :path_names => { :sign_up => "register", :sign_in => 'login', :sign_out => 'logout' }, :skip => [:passwords] do
scope :controller => 'devise/passwords' do
post :create, :path => 'user/password/new', :as => :user_password
get :new, :path => 'user/password/new' , :as => :new_user_password
end
end
in order to do a facebook invite automation i need to post specific data so that the facebook friend selection will open.
ill use this script on an already open event.
i think i just dont get the post() method, or it not used the way i want it.
im trying to run directly from the browser the method like this:
javascript:$.post('/events/create.php',{/ajax/choose/?type: 'event' eid: 'someeventid' send_invites_on_close: '1'});
or:
javascript:$.post('/events/create.php?eid=someeventid',{/ajax/choose/?type: 'event' eid: 'someeventid' send_invites_on_close: '1'});
any ideas?
thanks!
edit:
the html behind the post is:
<a class="mbs uiButton" role="button" href="/events/create.php?eid=*eventid*" rel="dialog-post" ajaxify="/ajax/choose/?type=event&eid=*eventid*&send_invites_on_close=1"><i class="mrs img sp_a2jb2c sx_c44d3d"></i><span class="uiButtonText">Select Guests to Invite</span></a>
The way of formatting parameters to JQuery post is like this (you were close, but need the commas to separate params) :
$.post("/events/create.php", { /ajax/choose/?type: 'event', eid: 'someeventid', send_invites_on_close: '1' });
(PS : not sure about whether your first param is legit without testing either - not sure about the special chars in there)