I'm trying to use in a script some DM functionalities and request.
My goal is on an event, sending a DM to a chosen follower.
For now, my working code is like this:
#!/usr/bin/perl
use strict;
use warnings;
use Net::Twitter::Lite::WithAPIv1_1;
my $twitter = Net::Twitter::Lite::WithAPIv1_1->new(
access_token_secret => 'XXX',
consumer_secret => 'XXX',
access_token => 'XXX',
consumer_key => 'XXX',
user_agent => 'Myself',
ssl => 1,
);
my $user = 'myself';
my $message_ack = "Hasta la vista, baby";
print "[sending: '$message_ack' to '$user'\n";
my $ack = $twitter->new_direct_message($user, $message_ack);
I have the following return:
# perl test.pl
[sending: 'Hasta la vista, baby' to 'myself'
new_direct_message expected 1 args at test.pl line 21.
I don't get is as the CPAN doc states that the 2 parameters given are required:
new_direct_message(user, text)
Parameters: user, text, screen_name, user_id, include_entities
Required: user, text
Sends a new direct message to the specified user from the
authenticating user. Requires both the user and text parameters.
Returns the sent message when successful. In order to support numeric
screen names, the screen_name or user_id parameters may be used
instead of user.
Returns: DirectMessage
Any hints on this one?
I've tried to google a bit on this, and I've found nothing really helpful. On some examples, they use the exact same thing as me (here for example: http://www.sevagas.com/Real-time-system-alerts-using-Twitter-OAuth-implementation on line 85)
I just figured it out with toolic comment.
So, there's the answer if someone ever have the same mistake :
Don't use
$twitter->new_direct_message($user, $message_ack);
but
$twitter->new_direct_message({ user => $user, text => $message_ack });
It looks like you have to pass a hashref, but I couldn't clearly see that hint in the doc.
Related
I was wondering if anybody has experience using the USAePay billing module? I have reached out to the developer and his response was he does not have time to help people. My problem is this -
I have written the following code to add a customer's billing information using the Sandbox server but it looks as though the module defaults to the production server so each time I attempt to validate the transaction I get the response -
Card was rejected: Specified source key not found.
How do I tell it to use the Sandbox server?
use strict;
use warnings;
use Business::OnlinePayment;
use constant {
LOGIN => 'source key', #USAePay source key
PASSWORD => '12345', #USAePay PIN
};
my $tx = new Business::OnlinePayment("USAePay");
$tx->content(
login => LOGIN,
password => PASSWORD,
type => 'CC',
action => 'Recurring Authorization',
description => 'Business::OnlinePayment test',
amount => '49.95',
invoice_number => '100100',
name => 'Tofu Beast',
card_number => '4000100011112224',
expiration => '09/19',
address => '1234 Bean Curd Lane',
city => 'San Francisco',
state => 'CA',
zip => '94102',
);
$tx->submit();
if($tx->is_success()) {
print 'Card processed successfully: '.$tx->authorization.'\n';
} else {
print 'Card was rejected: '.$tx->error_message."\n";
}
As Business::OnlinePayment::USAePay is a processor for Business::OnlinePayment, but doesn't have a lot of docs itself, a look at the docs of Business::OnlinePayment might help. It reveales the test_transaction method.
Most processors provide a test mode, where submitted transactions will not actually be charged or added to your batch, calling this function with a true argument will turn that mode on if the processor supports it, or generate a fatal error if the processor does not support a test mode (which is probably better than accidentally making real charges).
An untested example:
my $tx = new Business::OnlinePayment("USAePay");
$tx->test_transaction; # here
$tx->content(
login => LOGIN,
password => PASSWORD,
type => 'CC',
action => 'Recurring Authorization',
description => 'Business::OnlinePayment test',
amount => '49.95',
invoice_number => '100100',
name => 'Tofu Beast',
card_number => '4000100011112224',
expiration => '09/19',
address => '1234 Bean Curd Lane',
city => 'San Francisco',
state => 'CA',
zip => '94102',
);
$tx->submit();
Digging a bit deeper in the source of Business::OnlinePayment::USAePay shows that this particular processor actually has three different test modes.
# test_transaction(0): normal mode
# 1 : test mode (validates formatting only)
# 2 : use sandbox server
# 3 : test mode on sandbox server
It looks like you can set the server details in the constructor - it takes an optional hash of parameters beyond the processor name.
Have you tried something like:
my $tx = new Business::OnlinePayment(
"USAePay",
Server => 'https://sandbox.usaepay.com/gate'
);
I've been searching various sites for some help on this, but not getting very far. My goal is to check group membership once a login is successful. The login part works fine, but I want to get a list of groups of the logged in user to compare it to a particular one. If they are not a member of that group, they are logged out, the session is deleted and they are returned to the login page, otherwise they can continue.
Here is the code:
my $base = "ou=Groups,ou=Services,dc=example,cd=com";
my $mesg = $ldap->search(
filter=>"(uid=$userid)",
base=>"$base",
scope=>'children',
);
my #entries = $mesg->entries;
print("mesg = <BR>");
print(Dumper($mesg));
And here is the output of $mesg:
$VAR1 = bless( {
'parent' => bless( {
'net_ldap_version' => 3,
'net_ldap_scheme' => 'ldaps',
'net_ldap_debug' => 0,
'net_ldap_socket' => bless( \*Symbol::GEN0, 'IO::Socket::SSL' ),
'net_ldap_host' => 'ldap.example.com',
'net_ldap_uri' => 'ldap.example.com',
'net_ldap_resp' => {},
'net_ldap_mesg' => {},
'net_ldap_async' => 0,
'net_ldap_port' => '636',
'net_ldap_refcnt' => 1
}, 'Net::LDAPS' ),
'errorMessage' => 'NDS error: no such entry (-601)',
'ctrl_hash' => undef,
'resultCode' => 32,
'callback' => undef,
'mesgid' => 2,
'matchedDN' => '',
'controls' => undef,
'raw' => undef
}, 'Net::LDAP::Search' );
I can see the NDS message that says there's no such entry, so I'm assuming my search query is where the error lies, but the mistake is escaping me. Any suggestions? I've also tried without the scope=>'children' line, without any change.
Thanks.
Update:
This is what I ended up doing, and was successful.. had to tweak one of the other person's answers a bit, but ended up getting what I was looking for.
my $mesg = $ldap->search(
filter=>"(&(objectClass=group)(memberUid=$userid)(member=$userdn))",
base=>"$base",
scope=>'subtree',
attrs=>[qw(memberUid)],
);
my $searchresults = $mesg->as_struct;
my %searchhash = %$searchresults; # dereference the hash
my #members = # { $searchhash{$base}{memberuid} }; # pick out just the memberuid array from the hash
Then I basically iterated over the users in that group (#members) and if the logged in user was in there,
they were authenticated, if not, their session info got deleted and the script exited.
Not exactly the same answer as was given below, but we don't have uniquemember in our tree. Either way, hope this helps someone.
When you log the user in I presume you are performing a successful bind with their distinguished name.
I would search for the user in the group instead of searching for all of the users groups and looking for the specific group. I am also presuming that you are using the groupOfUniqueNames group objectclass to group your users. I would do something like this...
# assuming you already have this value in a variable from the authN step
my $user_dn = "cn=dave,ou=people,dc=example,dc=com"
my $base = "cn=GroupToCheck,ou=Groups,ou=Services,dc=example,cd=com";
my $mesg = $ldap->search(
filter=>"(uniquemember=$user_dn)",
base=>"$base",
scope=>'base'
);
If you get a result then the user is in the group. If you don't get any results then the user is not in the group.
If you really do want to get all of the groups though then this will return the group name from all of the group(s) for which the user is a member.
# assuming you already have this value in a variable from the authN step
my $user_dn = "cn=dave,ou=people,dc=example,dc=com"
my $base = "ou=Groups,ou=Services,dc=example,cd=com";
my $mesg = $ldap->search(
filter=>"(uniquemember=$user_dn)",
base=>"$base",
scope=>'sub',
attrs => ['cn']
);
I have a most simple task: I try to read programmatically a tweet given its ID. For the access to the Twitter API, I use Perl's Twitter::Net API .
In lack of a clear documentation of which methods Twitter::Net provides (the docu is very verbose on the search method, as if that would be the only method of interest, but it doesn't even provide a list of all supported methods), I had to work with trial and error.
Twitter's REST API doc says:
GET statuses/show/:id - returns a single Tweet, specified by the id
parameter. The Tweet's author will also be embedded within the tweet.
I create a Twitter::Net instance, using my credentials and the REST 1.1 trait,
my $nt = Net::Twitter->new(
traits => [ qw/API::RESTv1_1/ ],
consumer_key => '...',
consumer_secret => '...',
access_token => '...',
access_token_secret => '...',
ssl => 1
);
Now I tried
my $t = $nt->show( <tweet_id> );
with no success:
Tweets11.pm: Can't locate object method "show" via package "Net::Twitter_v4_01002_with__API_RESTv1_1__OAuth" at Tweets11.pm line 25.
Similar message with statuses instead of show.
How to afford this very simple task with Perl's Twitter::Net?
Per the docs for Twitter::Net, the method you want is actually show_status:
show_status
show_status(id)
Parameters: id, trim_user, include_entities, include_my_retweet
Required: id
Returns a single status, specified by the id parameter. The status's author will be returned inline.
Returns: Status
I've been messing around with the tumblr API with perl and have gotten several functions to work.
However, I can not get local image files to upload via perl.
Here is my code that works for URLs
use LWP::Authen::OAuth;
use JSON;
use Data::Dumper;
use strict;
my $ua = LWP::Authen::OAuth->new(
oauth_consumer_key => 'xxx',
oauth_consumer_secret => 'xxx',
oauth_token => 'xxx',
oauth_token_secret => 'xxx',
);
my $response;
$response = $ua->post( 'http://api.tumblr.com/v2/blog/mytumblr.tumblr.com/post', [
type => 'photo',
url => 'http://www.example.com/mypic.jpg' ,
caption => 'Test image 1',
]);
if ($response->is_success) {
print "it worked";
}
else {
print "it did not work \n \n \n \n";
print $response->as_string;
}
However, when i substitute "url" for "data" in the post parameters (as instructed in their API description here - http://www.tumblr.com/docs/en/api/v2#posting), I keep getting an error response from tumblr. I have tried several ways of entering the "data" parameter - as a path to the file, as a binary representation, as a URL encoded binary representation, as a url encoded base64 binary representation, stuck ech one of those values as a sole element in an array - I have tried all, and with each one I get a error message back from tumblr.
So, can someone please show me how to upload a local image file to tumblr?
I'm not entirely familiar with the tumblr API, but a quick googling found me this example: https://gist.github.com/derekg/1198576
I would try
$response = $ua->post( 'http://api.tumblr.com/v2/blog/mytumblr.tumblr.com/post', [
type => 'photo',
'data[0]' => $file_contents , ## LWP::Useragent should automatically urlencode this
caption => 'Test image 1',
]);
According to this answer https://stackoverflow.com/a/177866/810448, it's possible that "data[]" would also work in this situation.
I would also consider adding 'Content-type: application/x-www-form-urlencoded' to the request headers, if LWP::Useragent is not doing it already.
I'm tried use the multiples invitations method of facebook-graph API.
of according the documentation,this is the syntax to send multiples invitations:
/EVENT_ID/invited?users=USER_ID1,USER_ID2,USER_ID3
I wrote this code:
$ids = 'id123,id12345';
$ch = curl_init("https://graph.facebook.com/$e_id/invited?users=$ids?access_token={$token}");
curl_setopt_array($ch,
array(CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CUSTOMREQUEST => 'POST'
)
);
I'm getting the following error:
{"error":{"message":"(#114) An id must be a valid ID string (e.g., \"123\")","type":"OAuthException"}}
How I fix this? Thanks in advance. :)
As it is written in error message it should be numeric strings i.e. "12345" and not "id12345", try real uids and don't invite your own uid.
hope this helps