How to use the zillow api with ZillowR - r

I want to access the GetDeepSearchResults info from the Zillow API.
My code:
library(ZillowR)
zapi_key = getOption('Myapikey')
GetDeepSearchResults(
address = '600 S. Quail Ct.',
zipcode = '67114',
rentzestimate = FALSE,
api_key = zapi_key
)
Error:
Error in GetDeepSearchResults(address = "600 S. Quail Ct.", zipcode = "67114", :
unused arguments (zipcode = "67114", api_key = zapi_key)
Why does this error occur? What can I do to fix this?
Edit: I changed the code according to the comments and got this:
My code:
library(ZillowR)
zapi_key = getOption('myapikey')
GetDeepSearchResults(
address = '600 S. Quail Ct.',
citystatezip = '67114',
rentzestimate = FALSE,
zws_id = 'myapikey',
url = "http://www.zillow.com/webservice/GetDeepSearchResults.htm"
)
Output:
$request
$request$address
NULL
$request$citystatezip
NULL
$message
$message$text
[1] "Error: invalid or missing ZWSID parameter"
$message$code
[1] "2"
$response
NULL
How can I fix this?

The unused arguments error is typical when you pass arguments, which are not parts of the function. So R doesn't know what to do with those and returns the error. You can check the documentation of the function with ?GetDeepSearchResults
This shows you the usage:
GetDeepSearchResults(address = NULL, citystatezip = NULL,
rentzestimate = FALSE, zws_id = getOption("ZillowR-zws_id"),
url = "http://www.zillow.com/webservice/GetDeepSearchResults.htm")
To have this work, you have to set your id first with (you can create an id on https://www.zillow.com/howto/api/APIOverview.htm):
set_zillow_web_service_id("youractualkey")
So you function does not have the argument zipcode and api_key. Let's change your arguments to some which exist:
GetDeepSearchResults(address='600 S. Quail Ct.', citystatezip ='67114',
rentzestimate=FALSE)
You surely recognized I did not use your api_key. This is because the default:zws_id = getOption("ZillowR-zws_id") calls your global 'ZillowR-zws_id' which you just set with the set_zillow_web_service_id() command. So it's not necessary to change the default value. But you can skip this when you use zws_id ="youractualkey" from zillow
I made a random account I set up for validating. This gives me the output:
$request
$request$address
NULL
$request$citystatezip
NULL
$message
$message$text
[1] "Error: this account is not authorized to execute this API call"
$message$code
[1] "6"
$response
NULL
So I could successfully contact the server and my key was recognized. The account authority is not R related and has to be set on the website.

Related

Calling PATCH API method returns 400 error?

I'm trying to call a PATCH Method API within ABAP, but i am always getting code 400 back with error message that content type is not supported, its needed application/json which i am setting already in the code.
cl_http_client=>create_by_url(
EXPORTING
url = lv_url
IMPORTING
client = lo_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4 ).
* Set request parameter (Authorization)
lo_client->request->set_header_field(
name = mc_param_name_authorization
value = mc_auth_type_bearer && | { mv_access_token }|
).
* Set request parameter (apiKey)
lo_client->request->set_header_field(
name = mc_param_name_apikey
value = CONV string( ms_access_settings-api_key )
).
* Set request parameter (realm)
lo_client->request->set_header_field(
name = mc_param_name_realm
value = get_realm( mc_api_call_approve )
).
lo_client->request->set_method( 'PATCH' ).
lo_client->request->set_content_type( 'application/json' ).
lo_http_client->request->set_cdata( lv_body_json ).
lo_client->send( ).
lo_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4 ).

Im aware im trying to get data for multiple accounts but where can i specify that rather than receiving this error in R?

library(rgoogleads)
library(gargle)
token <- token_fetch()
token
gads_auth(email = 'xx#gmail.com'
Authentication complete.
ad_group_report <- gads_get_report(
resource = "ad_group",
fields = c("ad_group.campaign",
"ad_group.id",
"ad_group.name",
"ad_group.status",
"metrics.clicks",
"metrics.cost_micros"),
date_from = "2021-01-08",
date_to = "2021-01-10",
where = "ad_group.status = 'ENABLED'",
order_by = c("metrics.clicks DESC", "metrics.cost_micros")
)
i Multi account request
! The request you sent did not return any results, check the entered parameters and repeat the opposition.
Why do I receive this error? I have never received it in Radwords package. Where do I mention the argument for the multiple accounts?
https://cran.r-project.org/web/packages/rgoogleads/rgoogleads.pdf

R: search_fullarchive() and Twitter Academic research API track

I was wondering whether anyone has found a way to how to use search_fullarchive() from the "rtweet" package in R with the new Twitter academic research project track?
The problem is whenever I try to run the following code:
search_fullarchive(q = "sunset", n = 500, env_name = "AcademicProject", fromDate = "202010200000", toDate = "202010220000", safedir = NULL, parse = TRUE, token = bearer_token)
I get the following error "Error: Not a valid access token". Is that because search_fullarchive() is only for paid premium accounts and that doesn't include the new academic track (even though you get full archive access)?
Also, can you retrieve more than 500 tweets (e.g., n = 6000) when using search_fullarchive()?
Thanks in advance!
I've got the same problem w/ Twitter academic research API. I think if you set n = 100 or just skip the argument, the command will return you 100 tweets. Also, the rtweet package does not (yet) support the academic research API.
Change your code to this:
search_fullarchive(q = "sunset", n = 500, env_name = "AcademicProject", fromDate = "202010200000", toDate = "202010220000", safedir = NULL, parse = TRUE, token = t, env_name = "Your Environment Name attained in the Dev Dashboard")
Also The token must be created like this:
t <- create_token(
app = "App Name",
'Key',
'Secret',
access_token = '',
access_secret = '',
set_renv = TRUE
)

Authenticating API in R

I'm trying to access Bitfinex via api but struggling to properly authenticate my request. There is a Python example of what I want to do (https://gist.github.com/jordanbaucke/5812039) but I can't seem to get it to work in R.
key <- c("MY API KEY")
secret = c("MY API SECRET")
req <- GET("https://api.bitfinex.com/v1/balances",
authenticate(key, secret))
add_headers(X-BFX-APIKEY = key))
stop_for_status(req)
content(req)
Can someone tell me what I'm doing wrong?
/v1/balances is a Bitfinex authenticated endpoints, thus it requires the POST request with a proper handling of payload and headers.
Here is a working example from my own script:
library(httr)
key <- "..."
secret <- "..."
# payload JSON object, the request should refer to the URL
# nonce should always be greater than for previous calls
payload_json <- list(request = '/v1/account_infos', nonce = as.character(as.numeric(as.POSIXct(Sys.time()))))
# creating string from JSON payload
payload <- jsonlite::toJSON(payload_json, auto_unbox = TRUE)
# encoding payload string
payload_str <- base64enc::base64encode(charToRaw(as.character(payload)))
# adding three Bitfinex headers:
# X-BFX-APIKEY = key
# X-BFX-PAYLOAD = base64 encoded payload string
# X-BFX-SIGNATURE = sha384 encrypted payload string with the secret key
req <- POST("https://api.bitfinex.com/v1/account_infos",
add_headers('X-BFX-APIKEY' = key,
'X-BFX-PAYLOAD' = payload_str,
'X-BFX-SIGNATURE' = openssl::sha384(payload_str, key = secret))
)
content(req)
For creating "New Order" you only need to change the payload to something, like this:
payload_json <- list(request = '/v1/account_infos',
nonce = as.character(as.numeric(as.POSIXct(Sys.time()))),
symbol = 'BTCUSD',
amount = '0.3',
price = '1000',
exchange = 'bitfinex',
side = 'sell',
type = 'exchange market'
)
The rest of the code will work without changes.
For list of payload parameters check the Bitfinex API docs, e.g. "New Order".

HTTPS Communication Failure ABAP

I'm working on an application that should be connected to two web applications. The first web application is finished (http://example.com). Unfortunately, the second web application utilizing HTTPS (https://example.com) threw this error: Http_Communication_Failure SY-SUBRC = 1.
Here is my program:
FORM CHEKCV_LOG_PASS.
DATA : lv_flag TYPE flag,
iv_user TYPE CHAR20,
iv_pass TYPE CHAR20.
iv_user = 'username'.
iv_pass = 'Pw1-a83-333'.
IF sy-subrc IS NOT INITIAL.
ENDIF.
CONSTANTS: c_type_get VALUE 0,
c_type_post VALUE 1.
TYPES: BEGIN OF ty_parameter,
name TYPE string,
type TYPE char1,
value TYPE string,
END OF ty_parameter.
DATA ls_parameter TYPE ty_parameter.
DATA lt_parameters TYPE TABLE OF ty_parameter.
DATA lt_fields TYPE tihttpnvp.
DATA lv_url TYPE string.
DATA SOAP_ACTION TYPE string.
DATA lv_uri TYPE string.
DATA lv_value TYPE string.
DATA lv_name TYPE string.
DATA lt_html TYPE TABLE OF string.
DATA: lo_client TYPE REF TO if_http_client,
lc_content TYPE string,
xcontent_clear TYPE xstring,
contentencoding TYPE string.
DATA ls_field TYPE ihttpnvp.
DATA lc_url TYPE string.
DATA lv_user TYPE zvrs_veyes_user.
DATA lv_pass TYPE char32.
lv_user = iv_user.
lv_pass = iv_pass.
ls_parameter-name = '_username'.
ls_parameter-value = lv_user.
ls_parameter-type = c_type_post.
APPEND ls_parameter TO lt_parameters.
CLEAR ls_parameter.
ls_parameter-name = '_password'.
ls_parameter-value = lv_pass.
ls_parameter-type = c_type_post.
APPEND ls_parameter TO lt_parameters.
CLEAR ls_parameter.
LOOP AT lt_parameters INTO ls_parameter.
IF ls_parameter-type = c_type_post.
ls_field-name = ls_parameter-name.
ls_field-value = ls_parameter-value.
APPEND ls_field TO lt_fields.
ELSEIF ls_parameter-type = c_type_get.
IF lv_url = ''.
CONCATENATE '?' ls_parameter-name '=' ls_parameter-value
INTO lv_url.
ELSE.
CONCATENATE lv_url '&' ls_parameter-name '=' ls_parameter-value
INTO lv_url.
ENDIF.
ENDIF.
ENDLOOP.
lc_url = 'https://Example.com/login_check'.
CONCATENATE lc_url lv_url INTO lv_url.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_url
IMPORTING
client = lo_client
EXCEPTIONS
OTHERS = 1.
IF sy-subrc IS NOT INITIAL.
EXIT.
ENDIF.
CALL METHOD lo_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.
******************************************************************
******************************************************************
LOOP AT lt_fields INTO ls_field.
lo_client->request->if_http_entity~set_form_field(
name = ls_field-name value = ls_field-value ).
ENDLOOP.
CALL METHOD lo_client->request->set_header_field
EXPORTING
name = '~request_uri'
value = lv_url.
lo_client->propertytype_accept_cookie = 1.
CALL METHOD lo_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
OTHERS = 5.
IF sy-subrc <> 0.
ENDIF.
CALL METHOD lo_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
IF sy-subrc IS NOT INITIAL.
EXIT.
ENDIF.
CALL METHOD lo_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'GET'.
CALL METHOD lo_client->request->set_header_field
EXPORTING
name = '~request_uri'
value = lc_url.
CALL METHOD lo_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
OTHERS = 5.
IF sy-subrc <> 0.
ENDIF.
CALL METHOD lo_client->receive *HERE IS THE PROBLEME
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
IF sy-subrc IS NOT INITIAL.
EXIT.
ENDIF.
lc_content = lo_client->response->get_cdata( ).
endform.
Check the system variables SY-MSGxx for more information on the actual problem. Most likely cause: The server certificate is not signed by any CA that the SAP system is configured to trust. You might have to add the server and/or CA certificates to the PSE. WARNING: Don't do that unless you know what you are doing and have cleared this with your basis admins/infosec officials or you might end up opening security leaks in a critical system.

Resources