How to use Twitter Api To Get more than 20 list Members in a single request? - api

i want to get more than 20 users using the the twitter api in a single request
is there any parameter that specifies it?
i am using this api
http://api.twitter.com/1/Barelyme/Politics/members.xml?cursor=-1

According to the Twitter List API Docs:
http://apiwiki.twitter.com/Twitter-REST-API-Method:-GET-list-members
You cant get more than 20 in a single request.

If you're using twitteroauth by abraham, you can iterate through the pages of list members (this example assumes $connection is already defined by a functional implementation of twitteroauth):
$user = $connection->get('account/verify_credentials'); //Gets/Tests credentials
$listmembers = $connection->get("{$user->screen_name}/LISTNAMEORID/members"); //Gets first page of list members; MUST edit "LISTNAMEORID"
$pagevalue = ""; //Set page value for later use
if($listmembers->next_cursor == 0){ //There is only one page of followers
for ($j=0, $k=count($listmembers->users); $j<$k; $j++){
//Your actions here
//print_r($listmembers); //Displays the page of list members
}
} else { //There are multiple pages of followers
while ($pagevalue!=$listmembers->next_cursor){
for ($j=0, $k=count($listmembers->users); $j<$k; $j++){
//Your actions here
//print_r($listmembers); //Displays the page of list members
}
$pagevalue = $listmembers->next_cursor; //Increment the 'Next Page' link
$listmembers = $connection->get("{$user->screen_name}/LISTNAMEORID/members", array('cursor' => $pagevalue)); //Gets next page of list members; MUST edit "LISTNAMEORID"
}
}

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$listmembers = $connection->get("MexicoTimes/mexicanpoliticians/members");
$members = array();
while ($listmembers->next_cursor_str != "0") {
foreach($listmembers->users as $user)
$members[] = $user;
$cursor = $listmembers->next_cursor_str;
$listmembers = $connection->get("MexicoTimes/mexicanpoliticians/members", array('cursor' => $cursor));
}
This one worked for me with Abraham's Twitteroauth

Probably not though, you can poll multiple times > 1 for more data.
Given that twitter said you can't do it, you Probably can't

Related

Paypal Php Sdk - NotifyUrl is not a fully qualified URL Error

I have this code
$product_info = array();
if(isset($cms['site']['url_data']['product_id'])){
$product_info = $cms['class']['product']->get($cms['site']['url_data']['product_id']);
}
if(!isset($product_info['id'])){
/*
echo 'No product info.';
exit();
*/
header_url(SITE_URL.'?subpage=user_subscription#xl_xr_page_my%20account');
}
$fee = $product_info['yearly_price_end'] / 100 * $product_info['fee'];
$yearly_price_end = $product_info['yearly_price_end'] + $fee;
$fee = ($product_info['setup_price_end'] / 100) * $product_info['fee'];
$setup_price_end = $product_info['setup_price_end'] + $fee;
if(isset($_SESSION['discountcode_amount'])){
$setup_price_end = $setup_price_end - $_SESSION['discountcode_amount'];
unset($_SESSION['discountcode_amount']);
}
$error = false;
$plan_id = '';
$approvalUrl = '';
$ReturnUrl = SITE_URL.'payment/?payment_type=paypal&payment_page=process_agreement';
$CancelUrl = SITE_URL.'payment/?payment_type=paypal&payment_page=cancel_agreement';
$now = $cms['date'];
$now->modify('+5 minutes');
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$cms['options']['plugin_paypal_clientid'], // ClientID
$cms['options']['plugin_paypal_clientsecret'] // ClientSecret
)
);
use PayPal\Api\ChargeModel;
use PayPal\Api\Currency;
use PayPal\Api\MerchantPreferences;
use PayPal\Api\PaymentDefinition;
use PayPal\Api\Plan;
use PayPal\Api\Patch;
use PayPal\Api\PatchRequest;
use PayPal\Common\PayPalModel;
use PayPal\Api\Agreement;
use PayPal\Api\Payer;
use PayPal\Api\ShippingAddress;
// Create a new instance of Plan object
$plan = new Plan();
// # Basic Information
// Fill up the basic information that is required for the plan
$plan->setName($product_info['name'])
->setDescription($product_info['desc_text'])
->setType('fixed');
// # Payment definitions for this billing plan.
$paymentDefinition = new PaymentDefinition();
// The possible values for such setters are mentioned in the setter method documentation.
// Just open the class file. e.g. lib/PayPal/Api/PaymentDefinition.php and look for setFrequency method.
// You should be able to see the acceptable values in the comments.
$setFrequency = 'Year';
//$setFrequency = 'Day';
$paymentDefinition->setName('Regular Payments')
->setType('REGULAR')
->setFrequency($setFrequency)
->setFrequencyInterval("1")
->setCycles("999")
->setAmount(new Currency(array('value' => $yearly_price_end, 'currency' => $cms['session']['client']['currency']['iso_code'])));
// Charge Models
$chargeModel = new ChargeModel();
$chargeModel->setType('SHIPPING')
->setAmount(new Currency(array('value' => 0, 'currency' => $cms['session']['client']['currency']['iso_code'])));
$paymentDefinition->setChargeModels(array($chargeModel));
$merchantPreferences = new MerchantPreferences();
// ReturnURL and CancelURL are not required and used when creating billing agreement with payment_method as "credit_card".
// However, it is generally a good idea to set these values, in case you plan to create billing agreements which accepts "paypal" as payment_method.
// This will keep your plan compatible with both the possible scenarios on how it is being used in agreement.
$merchantPreferences->setReturnUrl($ReturnUrl)
->setCancelUrl($CancelUrl)
->setAutoBillAmount("yes")
->setInitialFailAmountAction("CONTINUE")
->setMaxFailAttempts("0")
->setSetupFee(new Currency(array('value' => $setup_price_end, 'currency' => $cms['session']['client']['currency']['iso_code'])));
$plan->setPaymentDefinitions(array($paymentDefinition));
$plan->setMerchantPreferences($merchantPreferences);
// ### Create Plan
try {
$output = $plan->create($apiContext);
} catch (Exception $ex){
die($ex);
}
echo $output->getId().'<br />';
echo $output.'<br />';
Been working with paypal php sdk for some days now and my code stop working.
So i went back to basic and i am still getting the same damn error.
I am trying to create a plan for subscription but getting the following error:
"NotifyUrl is not a fully qualified URL"
I have no idea how to fix this as i dont use NotfifyUrl in my code?
Could be really nice if anyone had an idea how to fix this problem :)
Thanks
PayPal did a update to their API last night which has caused problem within their SDK.
They are sending back null values in their responses.
I MUST stress the error is not on sending the request to PayPal, but on processing their response.
BUG Report : https://github.com/paypal/PayPal-PHP-SDK/issues/1151
Pull Request : https://github.com/paypal/PayPal-PHP-SDK/pull/1152
Hope this helps, but their current SDK is throwing exceptions.
Use below simple fix.
Replace below function in vendor\paypal\rest-api-sdk-php\lib\PayPal\Api\MerchantPreferences.php
public function setNotifyUrl($notify_url)
{
if(!empty($notify_url)){
UrlValidator::validate($notify_url, "NotifyUrl");
}
$this->notify_url = $notify_url;
return $this;
}
If you get the same error for return_url/cancel_url, add the if condition as above.
Note: This is not a permanent solution, you can use this until getting the update from PayPal.
From the GitHub repo for the PayPal PHP SDK, I see that the error you mentioned is thrown when MerchantPreferences is not given a valid NotifyUrl. I see you're setting the CancelUrl and ReturnUrl, but not the NotifyUrl. You may simply need to set that as well, i.e.:
$NotifyUrl = (some url goes here)
$obj->setNotifyUrl($NotifyUrl);
Reason behind it!
error comes from.
vendor\paypal\rest-api-sdk-php\lib\PayPal\Validation\UrlValidator.php
line.
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
throw new \InvalidArgumentException("$urlName is not a fully qualified URL");
}
FILTER_VALIDATE_URL: according to this php function.
INVALID URL: "http://cat_n.domain.net.in/"; // IT CONTAIN _ UNDERSCORE.
VALID URL: "http://cat-n.domain.net.in/"; it separated with - dash
here you can dump your url.
vendor\paypal\rest-api-sdk-php\lib\PayPal\Validation\UrlValidator.php
public static function validate($url, $urlName = null)
{
var_dump($url);
}
And then check this here: https://www.w3schools.com/PHP/phptryit.asp?filename=tryphp_func_validate_url
you can check here what character will reason for invalid.

Google Analytics API get Profile ID instead or with Domains

This is how I print Domains from any Google Analytics account. How do I print Profile IDs instead (or with the Domains)?
global $_params, $output_title, $output_body;
$output_title = 'Adwords';
$output_nav = '<li>Logout</li>'."\n";
$output_body = '<h1>Google Adwords Access demo</h1>
<p>The following domains are in your Google Adwords account</p><ul>';
$props = $service->management_webproperties->listManagementWebproperties("~all");
foreach($props['items'] as $item) {
$output_body .= sprintf('<li>%1$s</li>', $item['name']);
}
$output_body .= '</ul>';
This line is the function that gets the Domains:
$props = $service->management_webproperties->listManagementWebproperties("~all");
I need something to get Profile IDs for multiple Domains now.
Thanks in advance.
This example below should help you print all the profile ids for a particular account XXXX and property UA-XXXX-Y.
/**
* This example requests a list of views (profiles) for the authorized user.
*/
$profiles = $analytics->management_profiles->listManagementProfiles('XXXX', 'UA-XXXX-Y');
foreach ($profiles->getItems() as $profile) {
print("view (profile) id: $profile->getId()");
}
You can checkout the API documentation for view (profiles) for more detailed examples.
You may also find it useful to use the account summaries api. It provides an easy way to iterate through all levels of the Google Analytics Accounts -> Properties -> view (profiles)
$accounts = $analytics->management_accountSummaries
->listManagementAccountSummaries();
foreach ($accounts->getItems() as $account) {
$html = <<<HTML
<pre>
Account id = {$account->getId()}
Account kind = {$account->getKind()}
Account name = {$account->getName()}
HTML;
// Iterate through each Property.
foreach ($account->getWebProperties() as $property) {
$html .= <<<HTML
Property id = {$property->getId()}
Property kind = {$property->getKind()}
Property name = {$property->getName()}
Internal property id = {$property->getInternalWebPropertyId()}
Property level = {$property->getLevel()}
Property URL = {$property->getWebsiteUrl()}
HTML;
// Iterate through each view (profile).
foreach ($property->getProfiles() as $profile) {
$html .= <<<HTML
Profile id = {$profile->getId()}
Profile kind = {$profile->getKind()}
Profile name = {$profile->getName()}
Profile type = {$profile->getType()}
HTML;
}
}
$html .= '</pre>';
print $html;
}

auth url doesn't work in yahoo

I am doing login with yahoo from my site.
I used the code given from https://github.com/yahoo/yos-social-php
snippet of sample code:
$hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
if($hasSession == FALSE) {
// create the callback url,
$callback = YahooUtil::current_url()."?in_popup";
$sessionStore = new NativeSessionStore();
$auth_url = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback, $sessionStore);
}
here the $auth_url gives empty value. its return null. Also I given correct consumer-key, secret-key and app-id.
You have to replace your current Yahoo Api library with the below github branch.
https://github.com/syamvilakudy/yos-social-php

Eventbrite API date range parameter for organizer_list_events

I need a way to search via the eventbrite api past events, by organizer, that are private, but I also need to be able to limit the date range. I have not found a viable solution for this search. I assume the organizer_list_events api would be the preferred method, but the request paramaters don't seem to allow for the date range, and I am getting FAR too many returns.
I'm having some similar issues I posted a question to get a response about parsing the timezone, here's the code I'm using to get the dates though and exclude any events before today (unfortunately like you said I'm still getting everything sent to me and paring things out client side)
Note this is an AngularJS control but the code is just using the EventBrite javascript API.
function EventCtrl($http, $scope)
{
$scope.events=[];
$scope.noEventsDisplay = "Loading events...";
Eventbrite({'app_key': "EVC36F6EQZZ4M5DL6S"}, function(eb){
// define a few parameters to pass to the API
// Options are listed here: http://developer.eventbrite.com/doc/organizers/organizer_list_events/
//3877641809
var options = {
'id' : "3588304527",
};
// provide a callback to display the response data:
eb.organizer_list_events( options, function( response ){
validEvents = [];
var now = new Date().getTime();
for(var i = 0; i<response.events.length; i++)
{
var sd = response.events[i].event.start_date;
var ed = response.events[i].event.end_date;
var parsedSD = sd.split(/[:-\s]/);
var parsedED = ed.split(/[:-\s]/);
var startDate = new Date(parsedSD[0], parsedSD[1]-1, parsedSD[2], parsedSD[3], parsedSD[4], parsedSD[5]);
var endDate = new Date(parsedED[0], parsedED[1]-1, parsedED[2], parsedED[3], parsedED[4], parsedED[5]);
if(endDate.getTime()<now)
continue;
response.events[i].event.formattedDate = date.toDateString();
validEvents.push(response.events[i])
}
if(validEvents.length == 0)
{
$scope.$apply(function(scope){scope.noEventsDisplay = "No upcoming events to display, please check back soon.";});
}
else
{
$scope.$apply(function(scope){scope.noEventsDisplay = "";});
}
$scope.$apply(function(scope){scope.events = validEvents;});
//$('.event_list').html(eb.utils.eventList( response, eb.utils.eventListRow ));
});
});
}

Ebay API with description

How do I get the Ebay API to return a description?
I have some code that makes an API call as follows:
http://svcs.ebay.com/services/search/FindingService/v1?
callname=findItemsAdvanced&
responseencoding=XML&
appid=appid&
siteid=0&
version=525&
QueryKeywords=keywords;
It returns items, but it's missing the full description text. I'm not seeing the next step to ask for the detailed descriptions.
You have to use Shopping API, for instance: http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetSingleItem.html#sampledescriptionitemspecifics
I use following (very simple function to get Item detail from ebay):
function eBayGetSingle($ItemID){
$URL = 'http://open.api.ebay.com/shopping';
//change these two lines
$compatabilityLevel = 967;
$appID = 'YOUR_APP_ID_HERE';
//you can also play with these selectors
$includeSelector = "Details,Description,TextDescription,ShippingCosts,ItemSpecifics,Variations,Compatibility";
// Construct the GetSingleItem REST call
$apicall = "$URL?callname=GetSingleItem&version=$compatabilityLevel"
. "&appid=$appID&ItemID=$ItemID"
. "&responseencoding=XML"
. "&IncludeSelector=$includeSelector";
$xml = simplexml_load_file($apicall);
if ($xml) {
$json = json_encode($xml);
$array = json_decode($json,TRUE);
return $array;
}
return false;
}