I'm trying to get my emails using the Gmail gem (source) with the next call:
class MyClass
def initialize account, credentials
#gmail = Gmail.connect(account, credentials)
end
def get_attachments received_at, options
mails = #gmail.inbox.find(
:to => options[:to],
:has=>:attachments,
:before => options[:end_date],
:after => received_at
)
#more code
end
end
#gmail is a valid instance of Gmail class, and this call raises sometimes the next error:
Unknown command v2if4084974eef.9
The command (v2if4084974eef.9) changes in every call I make.
What am I doing wrong?
[Edit]
The error raised in specs is this
1)
Net::IMAP::BadResponseError in 'MailFacade get_data should return an array'
Unknown command v17if3069084anm.44
I had this issue and I found the answer to this in the last comment on this link:
https://github.com/nu7hatch/gmail/issues/36
You just have to follow these steps:
1. Go to your Google account settings: myaccount.google.com
2. Click on "connected apps & sites" option.
3. Turn "Allow less secure apps" to "ON" (near the bottom of the page).
That's it, at least works for me, hope it works for you aswell.
Greetings from Bolivia!!
You need to allow "less secure" apps to use your Gmail account (as #xXAngelJinXx mentioned). Since Google changed the UI, now one needs to do the following:
Go to your Google account settings: https://myaccount.google.com
Click on "Security" on the left
Scroll down to "Less secure app access"
Click on "Turn on access (not recommended)"
Turn it to "ON".
Related
I'm implementing an invisible reCAPTCHA as per the instructions in the documentation: reCAPTCHA V2 documentation
I've managed to implement it without any problems. But, what I'd like to know is whether I can simulate being a robot for testing purposes?
Is there a way to force the reCAPTCHA to respond as if it thought I was a robot?
Thanks in advance for any assistance.
In the Dev Tools, open Settings, then Devices, add a custom device with any name and user agent equal to Googlebot/2.1.
Finally, in Device Mode, at the left of the top bar, choose the device (the default is Responsive).
You can test the captcha in https://www.google.com/recaptcha/api2/demo?invisible=true
(This is a demo of the Invisible Recaptcha. You can remove the url invisible parameter to test with the captcha button)
You can use a Chrome Plugin like Modify Headers and Add a user-agent like Googlebot/2.1 (+http://www.google.com/bot.html).
For Firefox, if you don't want to install any add-ons, you can easily manually change the user agent :
Enter about:config into the URL box and hit return;
Search for “useragent” (one word), just to check what is already there;
Create a new string (right-click somewhere in the window) titled (i.e. new
preference) “general.useragent.override”, and with string value
"Googlebot/2.1" (or any other you want to test with).
I tried this with Recaptcha v3, and it indeed returns a score of 0.1
And don't forget to remove this line from about:config when done testing !
I found this method here (it is an Apple OS article, but the Firefox method also works for Windows) : http://osxdaily.com/2013/01/16/change-user-agent-chrome-safari-firefox/
I find that if you click on the reCaptcha logo rather than the text box, it tends to fail.
This is because bots detect clickable hitboxes, and since the checkbox is an image, as well as the "I'm not a robot" text, and bots can't process images as text properly, but they CAN process clickable hitboxes, which the reCaptcha tells them to click, it just doesn't tell them where.
Click as far away from the checkbox as possible while keeping your mouse cursor in the reCaptcha. You will then most likely fail it. ( it will just bring up the thing where you have to identify the pictures).
The pictures are on there because like I said, bots can't process images and recognize things like cars.
yes it is possible to force fail a recaptcha v2 for testing purposes.
there are two ways to do that
First way :
you need to have firefox browser for that just make a simple form request
and then wait for response and after getting response click on refresh button firefox will prompt a box saying that " To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier. " then click on "resend"
by doing this browser will send previous " g-recaptcha-response " key and this will fail your recaptcha.
Second way
you can make any simple post request by any application like in linux you can use curl to make post request.
just make sure that you specify all your form filed and also header for request and most important thing POST one field name as " g-recaptcha-response " and give any random value to this field
Just completing the answer of Rafael, follow how to use the plugin
None of proposed answers worked for me. I just wrote a simple Node.js script which opens a browser window with a page. ReCaptcha detects automated browser and shows the challenge. The script is below:
const puppeteer = require('puppeteer');
let testReCaptcha = async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto('http://yourpage.com');
};
testReCaptcha();
Don't forget to install puppeteer by running npm i puppeteer and change yourpage.com to your page address
I am able to use both prompt=consent and prompt=select_account individually, but Google doesn't seem to allow me to combine them. I tried the prompt=consent+select_account as suggested in an answer of Force google account chooser, but that fails with the error: "Invalid prompt: consent+select_account".
The doc (https://developers.google.com/accounts/docs/OAuth2Login) says "A space-delimited list", so I tried consent select_account but that fails with: "The requested URL was not found on this server."
I also tried combining prompt=select_account and approval_prompt=force, but Google doesn't like that either.
Anyone else have luck with combining consent screen and account chooser?
Update:
This is my JavaScript method creating URL for getting contacts from gmail
$scope.importGmailContacts = function() {
provider = 'gmail';
$scope.importing_from_gmail = true;
window.open(protocol + "://" + host + ":" + port + "/contacts/gmail", "_blank",
"toolbar=yes, scrollbars=yes, resizable=yes, top=0, left=0, width=600, height=600, prompt='select_account+consent', approval_prompt=force");
}
I have tried setting prompt and approval_prompt both collectively and individually but it does not seems to work. Refer to this question.
You need add: access_type=online&prompt=select_account+consent:
private static final String AUTHORIZE_URL
= "https://accounts.google.com/o/oauth2/auth?"
+ "response_type=code&access_type=online&prompt=select_account+consent"
+ "&client_id=xxx&redirect_uri=xxx";
private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=xxx";
..
I just tried this and it DID work when space-delimited:
options[:prompt] = 'select_account consent'
https://accounts.google.com/o/oauth2/auth?client_id=XXXX&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/analytics.readonly&response_type=code&prompt=select_account+consent&approval_prompt=force
Results in the error
That’s an error.
Error: invalid_request
Conflict params: approval_prompt and prompt
Prompt and approval_prompt parameters can not be used together.
prompt Optional. A space-delimited, case-sensitive list of prompts to present the user. If you don't specify this parameter, the user will be prompted only the first time your app requests access. Possible values are:
none Do not display any authentication or consent screens. Must not be specified with other values.
consent Prompt the user for consent.
select_account Prompt the user to select an account.
If memory serves approval_prompt is the older way of doing it and google added Prompt sometime in 2012. I cant actually find any documentation on approval_prompt anymore but if memory serves it was the same as doing prompt=consent it just requested access again.
I've written some Ruby code (connected with Cucumber) that will go to a website and click a file that I'd like to download. The browser I'm using for this is Google Chrome.
Typically, when you go to download a file in Chrome, it doesn't ask for permission. However, when I run the code I made, it says:
"This type of file can harm your computer. Do you want to keep file_name.exe anyway?" It gives 2 options, "keep" or "discard". I have to click keep.
Obviously, you don't want all executables to just start downloading; however, this particular website/file should always be trustworthy.
Is there a command in Ruby or Cucumber that allows you to click the "keep" button automatically? This could just be a general "click at this pixel" or something. Or is there a way to mark a particular website in Chrome as safe. You can't inspect the element because it's not part of the website, but, instead, part of the browser. Preferably without having to download other software.
With this being said, this suggests that if it is possible, it should also be possible to automate an installation (as in clicking next -> next -> etc) for you. Hopefully this is correct?
Thanks in advance.
You can implement it in any browser. But, for Google Chrome, here is the solution -
profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = "Absolute or relative path to your download directory"
browser = Selenium::WebDriver.for :chrome, :profile => profile
You haven't specified which gem you use for browser. But, even if you use watir-webdriver, you can use the same profile you created above with watir-webdriver.
browser = Watir::Browser.new :chrome, :profile => profile
I actually switched to using Sikuli, which worked pretty well. Thanks for the help, though.
Do you really need or want the browser to download the file? Are you really testing the browser's download feature, or do you want to verify that the server can serve the file and that it is what you expect?
I found the idea of setting up a default directory and having to check for the file clumsy, fragile and prone to errors, especially when setting up on a new host, especially for tests that run in multiple browsers.
My solution is to just use Ruby (or whatever language) features to download the file directly, and then validate that it is the file it's supposed to be. I'm not testing the browser, I'm testing the software. The only exception to that idea I can think of is if you use some javascript logic or something browser-dependent to redirect you to a link, but please don't ever do that.
However, you run into a problem if you have to log in to access your file; you either have to implement auth in your Ruby code, which isn't technically part of your Cucumber specification, or you need the cookies. I use this code to copy the cookies to avoid logging in again, and grab the file:
def assert_file_link(uri, filename, content_type)
f = open_uri_with_cookies uri
attachment_filename = f.meta["content-disposition"].sub("Attachment;filename=", "") # "Attachment;filename=Simple Flow - Simple Form.rtf"
content_length = Integer(f.meta["content-length"])
assert(f.status == ["200", "OK"], "Response was not 200 OK")
assert(f.content_type == content_type, "Expected content-type of '#{content_type}' but was '#{f.content_type}'")
assert(attachment_filename == filename, "Expected filename of '#{filename}' but was '#{attachment_filename}'")
assert(content_length > 0, "Expected content-length > 0 but was '#{content_length}'")
end
def open_uri_with_cookies(uri)
# hack the cookies from the existing session so we don't need to log in!
cookies = ""
#driver.manage.all_cookies.each { |cookie| cookies.concat("#{cookie[:name]}=#{cookie[:value]}; ") }
if block_given?
open(uri, "Cookie" => cookies, :proxy => nil) do |f|
yield f
end
else
open(uri, "Cookie" => cookies, :proxy => nil)
end
end
Hope this helps.
I am trying to use the LinkedIn gem to access LinkedIn. I can't seem to get past getting access.
My code is this:
#client = LinkedIn::Client.new(API_KEY, SECRET)
#rtoken = client.request_token.token
#rsecret = client.request_token.secret
puts "token: #{#rtoken} secret #{#rsecret}"
#authorize_url = client.request_token.authorize_url
puts "authorize url: #{#authorize_url}"
#pin = #authorize_url.split("oauth_token=").last.strip
puts "pin #{#pin}"
#keys = #client.authorize_from_request(#rtoken, #rsecret, #pin)
#client.authorize_from_access(#keys)
And that produces the error:
token: sdklghsdgksdghskdhg secret shdlgkshdgshsdk
authorize url: https://www.linkedin.com/uas/oauth/authorize?oauth_token=sdkghskldghsdkg
pin fslkdghskdghdsgkhsdkhg
OAuth::Problem: permission_unknown
Not really sure where to start on this. I've tried to find what permission is missing, but I'm at a loss.
Thoughts?
I've just started playing with this myself. I hit this same issue unless I manually paste the authorize URL into my browser, and then click Accept to allowing the requested permissions to my account. Then a pin is printed on the screen which I enter in for the authorize_from_request call.
So this line in your code is incorrect - the last part of the URL is a generated_token as the README indicates, not a pin. I'm not sure of a programmatic way to do this.
#pin = #authorize_url.split("oauth_token=").last.strip
I discovered the issue. It turns out request_token.authorize_url does not return the pin. It just gives you a URL to visit where you can authenticate and generate a pin. Then you'll have to copy the pin into your application. A more elegant solution is this:
puts request_token.authorize_url
puts "Access the URL above. Authenticate. Enter the PIN here:"
pin = gets.strip
access_keys = client.authorize_from_request(rtoken, rsecret, pin)
This prints the URL and directs the user to authenticate, then enter the pin into the application.
I read the documentation of the Dropbox SDK for Ruby, and couldn't find an example about using my own dropbox account. The examples I saw require that I get an ACCESS_TOKEN from a random user that validates the session for me.
I am the user! I just want to start uploading and deleting files; nothing more.
How do I achieve that?
EDIT:
snippet
require 'dropbox_sdk'
APP_KEY = '******'
APP_SECRET = '*****'
ACCESS_TYPE = :dropbox
session = DropboxSession.new(APP_KEY, APP_SECRET)
#I don't want to do this, I just want to know the way of authenticate
#myself with some method that don't need authorization
#-------------------------------------------
session.get_request_token
authorize_url = session.get_authorize_url
puts "AUTHORIZING", authorize_url
puts "Please visit that website and hit 'Allow', then hit Enter here."
gets
session.get_access_token
client = DropboxClient.new(session, ACCESS_TYPE)
puts "linked account:", client.account_info().inspect