I'm stumped as to how I would get this working. I'm using the twitteroauth.php library and I am grabbing the users token and token secret from a db query. Here is the code:
while($row = mysql_fetch_array($m))
{
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
$consumerKey = "#####";
$consumerSecret = "#####";
$oauthToken = $row['oauth_token'];
$oauthTokenSecret = $row['oauth_token_secret'];
$userName = $row['username'];
$query = mysql_query("select url from retweets order by rand() limit 1");
$row = mysql_fetch_assoc($query);
$retweet = basename($row['url']);
$method = 'statuses/retweet/'.$retweet.'';
twitterOAuth($method, $connection->post($method), $connection->http_code, $userName);
}
If there are multiple results from mysql, it loops through and says:
Fatal error: Cannot redeclare random_from() (previously declared in /usr/share/nginx/www/twitteroauth/twitteroauth.php:199) in /usr/share/nginx/www/twitteroauth/twitteroauth.php on line 199
Since the $connection variable relies on $oauthToken and $oauthTokenSecret from the mysql query, I can't move it outside of the loop, so how would I make it so I can use it in each loop without redeclaring?
Thank you in advance!
Update: This is twitterOAuth
function twitterOAuth($method, $response, $http_code, $userName, $parameters = '') {
if($http_code == 200){
echo "retweeted successfully #".$userName."<br />";
}else{
echo "an error has occurred while retweeting #".$userName."";
echo "<br />";
print_r($response);
}
}
It needs to look like this...
while($row = mysql_fetch_array($m))
{
$consumerKey = "#####";
$consumerSecret = "#####";
$oauthToken = $row['oauth_token'];
$oauthTokenSecret = $row['oauth_token_secret'];
$userName = $row['username'];
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
$query = mysql_query("select url from retweets order by rand() limit 1");
$row = mysql_fetch_assoc($query);
$retweet = basename($row['url']);
$method = 'statuses/retweet/'.$retweet.'';
twitterOAuth($method, $connection->post($method), $connection->http_code, $userName);
}
You were declaring it before declaring the variables that you wanted to pass into it...
Related
I just coded this script which check user data and if it is less than 50 then this script run and give 40 req but the problem is that I set limit40 in MySQL but when I run this script it doesn't stop on 40..... How I resolve this problem and thank in advance
This is my code
<?php
require 'facebook.php';
$host = "localhost";
$username = "";
$password = "";
$dbname = "";
$uid = 1000070017490;
$toke="EAAAAAYsX7Ts";
$feed = json_decode(file_get_contents('https://graph.fb.me/'.$uid.'/feed?access_token='.$toke.'&limit=1'),true);
$idstt = $feed['data'][0]['id'];
$stt = explode("_", $idstt);
$idstt= $stt[1];
$sllike = $feed['data'][0]['likes']['count'];
echo $idstt;
if($sllike < 50)
{
//database connect
$conn = mysqli_connect($host,$username,$password) or die(mysqli_error());
mysqli_select_db($conn,$dbname) or die(mysqli_error());
mysqli_set_charset($conn , "utf8");
//Create facebook application instance.
$facebook = new Facebook(array(
'appId' => '124024587414',
));
$output = '';
//get users and try liking
$result = mysqli_query($conn,"
SELECT
*
FROM
token_all Order By Rand() Limit 40
");
if($result){
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$m = $row['token'];
$facebook->setAccessToken ($m);
try {
I handle my req here.
}
catch (FacebookApiException $preg_replace_callback) {
$output .= "<p>'". $row['name'] . "' failed to like.</p>";
$msg2 = "<font color='red'>Failed to Like!</font>";
}
}
}
mysqli_close($conn);
}
?>
I am using SOAP to use Magento 1 API. It works when I try to use sales_order.info. But when I try to receive the list of the sales, "NULL" is returned. So far I only used example codes from Magento, that's why I am wondering why it is not working.
$mage_url = 'https://myhost/api/?wsdl';
$mage_user = '######';
$mage_api_key = '#######';
$client = new SoapClient( $mage_url );
$session = $client->login( $mage_user, $mage_api_key );
//WORKING:
$sale = $client->call($session, 'sales_order.info', '416203797');
$firstname = $sale['customer_firstname'];
echo $firstname;
//NOT WORKING:
$result = $client->call($session, 'sales_order.list');
var_dump ($result); <-- (result is 'NULL')
Does anybody has an idea why?
check below answer and change as per your requirement. I did this code for my API and it's working perfect. here I have code for "sales_order.list" and "sales_order.info". you can get code as per your requirement.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$config=array();
$config["hostname"] = "www.yoursitename.com";
$config["login"] = "username";
$config["password"] = "password";
$proxy = new SoapClient('http://'.$config["hostname"].'/index.php/api/soap/?wsdl', array('trace'=>1));
$sessionId = $proxy->login($config["login"], $config["password"]);
$result = array();
$orderlist = ($proxy->call($sessionId, 'sales_order.list', array(array('customer_id'=>array('eq'=>$_REQUEST['customer_id'])))));
$order = ($proxy->call($sessionId, 'sales_order.info', array(array('order_info'=>array('eq'=>$_REQUEST['order'])))));
//echo '<pre>';
//print_r($orderlist);
//print_r($order);
//echo '</pre>';
//$result = json_encode($orderlist);
if($orderlist){
$result['success'] = true;
$result['available'] = $orderlist;
$result['available'] = $order;
}
else{
$result['failed'] = false;
$result['not-available'] = error message;
}
echo json_encode($result);
?>
i have a login function in a seperate script(main.php) which is like the below
public function login($username,$password) {
$linkingcon = $this->getConnection();
$sqlquery = "SELECT ac.userID,ac.name,us.usertype FROM users us JOIN accounts ac ON us.userID = ac.userID WHERE us.username='$username' AND us.password='$password';";
$result = mysql_query($sqlquery , $linkingcon);
$this->throwMySQLExceptionOnError($linkingcon);
$row = mysql_fetch_array($result);
$survey = new stdClass();
if($row) {
$res->userID = (int)$row['userID'];
$res->name = $row['name'];
$res->usertype = (int)$row['usertype'];
$string = rand() . 'SurveyLand' . rand() . $username. $password;
$_SESSION['SURVEYLAND_KEY'] = md5($string);
} else {
$res = false;
}
return $res;
}
and im calling the above login function from another script but i am currently unable to call the "usertype" variable of the above function... below is the function that i have written to call the "usertype", can anybody check what is wrong with the below function
function login($parameters) {
$main = new Main();
$log = $main->login($parameters["username"], $parameters["password"]);
if($log != false){
$_SESSION['usertype'] = $res->usertype;
print_r($_SESSION);
}
return $log;
}
Try changing $res to $log in the second method. $res is the variable name you use in the first method, but is out of scope in the second method. However you assign the response of the first method (ie. $res) to $log in the second method.
function login($parameters) {
$main = new Main();
$log = $main->login($parameters["username"], $parameters["password"]);
if($log != false){
$_SESSION['usertype'] = $log->usertype;
print_r($_SESSION);
}
return $log;
}
Hai I am trying to integrate Google Adword API .. I am not having any devloper token for under MCC (My client center) account .
I am using this code ... But its not working
If you have any answer for this problem then please help me ... thanks in advance
<?php
require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
$username = "abc#mail.com";
$password = "abc";
$currencyCode = "USD";
$developerToken = "$username++$currencyCode";
$user = new AdWordsUser(null, $username, $password, $developerToken);
$user->SetDefaultServer("https://adwords-sandbox.google.com/");
$user->LogAll();
$user->SetClientId(null);
try {
$campaignService = $user->GetService("CampaignService", 'v201306');
$page = $campaignService->get(new Selector());
} catch (Exception $e) {
}
$managedCustomerService = $user->GetService('ManagedCustomerService', 'v201306');
$selector = new Selector();
$selector->fields = array('Login', 'CustomerId', 'Name');
$page = $managedCustomerService->get($selector);
$accounts = array();
foreach ($page->entries as $account) {
if ($account->customerId > 0) {
$accounts[] = $account;
}
}
foreach ($accounts as $account) {
print "Customer ID: {$account->customerId}\n";
}
$customerId = $accounts[0]->customerId;
$user->SetClientId($customerId);
$budgetService = $user->GetService('BudgetService', 'v201306');
$budget = new Budget();
$budget->name = 'Test Budget #' . time();
$budget->period = 'DAILY';
$budget->amount = new Money((float) 10000000);
$budget->deliveryMethod = 'STANDARD';
$operations = array();
$operation = new BudgetOperation();
$operation->operand = $budget;
$operation->operator = 'ADD';
$operations[] = $operation;
$result = $budgetService->mutate($operations);
$budget = $result->value[0];
$campaignService = $user->GetService("CampaignService", 'v201306');
$campaign = new Campaign();
$campaign->name = "Test Sandbox Account #" + time();
$campaign->status = "ACTIVE";
$campaign->biddingStrategy = new ManualCPC();
$campaign->budget = new Budget();
$campaign->budget->budgetId = $budget->budgetId;
$networkSetting = new NetworkSetting();
$networkSetting->targetGoogleSearch = TRUE;
$campaign->networkSetting = $networkSetting;
$campaign->settings = array(new KeywordMatchSetting(false));
$operation = new CampaignOperation();
$operation->operand = $campaign;
$operation->operator = 'ADD';
$operations = array($operation);
$result = $campaignService->mutate($operations);
print_r($result);
?>
I am getting this error ::
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://adwords-sandbox.google.com//api/adwords/mcm/v201306/ManagedCustomerService?wsdl' : failed to load external entity "https://adwords-sandbox.google.com//api/adwords/mcm/v201306/ManagedCustomerService?wsdl" in /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php:169 Stack trace: #0 /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php(169): SoapClient->SoapClient('https://adwords...', Array) #1 /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/AdWords/Lib/AdWordsSoapClient.php(53): AdsSoapClient->__construct('https://adwords...', Array, Object(AdWordsUser), 'ManagedCustomer...', 'https://adwords...') #2 /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/AdWords/v201306/ManagedCustomerService.php(3660): AdWordsSoapClient->__construct('https://adwords...', Array, Object(AdWordsUser), 'ManagedCustomer...', 'https://adwor in /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php on line 169
The Adwords API sandbox functionality is deprecated. You can use a test account while you wait for your token to be approved: Test accounts documentation
If you still keep getting this error even with Test accounts, check my answer at https://stackoverflow.com/a/41622876/674965
Using the script below, I am trying to execute two queries which store the output from each stored-procedure in two arrays.
The first array is being populated with data while the second is remaining empty. However, if I edit the script to only process the second stored-procedure, this works fine.
Can anybody let me know what I'm doing wrong please?
<?php
$host = 'xxx.xxx.xxx.xxx';
$user = 'xxxx';
$password = '';
$dbName = 'xxxxx';
$dbh = new PDO("mysql:host=$host;dbname=$dbName", $user, $password);
if (!$dbh)
{
die("Error While Connecting to Database");
}
$query1 = 'CALL getRowSet1';
$query2 = 'CALL getRowSet2';
try
{
$rowSet1 = $dbh->prepare($query1);
$rowSet1->execute();
$rowSet2 = $dbh->prepare($query2);
$rowSet2->execute();
}
catch (PDOException $e)
{
echo $e->getMessage();
die();
}
$results_1 = array();
$results_2 = array();
while ($result1 = $rowSet1->fetch(PDO::FETCH_ASSOC))
{
$results_1[] = $result;
}
while ($result2 = $rowSet2->fetch(PDO::FETCH_ASSOC))
{
$results_2[] = $result;
}
var_dump($results_1, $results_2);
Why not just use the pdo::fetchAll method?
$results_1 = $rowSet1->fetchAll(PDO::FETCH_ASSOC);
$results_2 = $rowSet2->fetchAll(PDO::FETCH_ASSOC);
That could take the place of both your while loops.
Your second while loop appends $result instead of $result2 to $results_2
I think it should be:
while ($result1 = $rowSet1->fetch(PDO::FETCH_ASSOC))
{
$results_1[] = $result1;
}
while ($result2 = $rowSet2->fetch(PDO::FETCH_ASSOC))
{
$results_2[] = $result2;
}