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
Related
public function sofyAction()
{
$args = [ 'config_key' => $this->getConfigKey() ];
$sofy = new Api($args);
$helper = $this->getServiceLocator()->get('ViewHelperManager')->get('ServerUrl');
$successUrl = $helper($this->url()->fromRoute('sofort_response'));
$params = [
'amount' => 1500,
'currency_code' => 'EUR',
'reason' => 'Vouhcer Order',
'success_url' => $successUrl,
'customer_protection' => false,
'notification_url' => 'MY_PRIVATE_RESPONSE_URL',
];
$trans = $sofy->createTransaction($params);
return $this->redirect()->toUrl($trans['payment_url']);
}
How to get response and transaction ID as given it API document in Notification URL and on success URL too , please unable to find any help or guide for it ?
The easiest way is to let Payum do notification related job for you. To do so you either:
have to create manually a notification token using Payum's token factory (I am not sure it is present in the Zend module, it is quite old). Use the token as notification_url. Nothing more. Sofort will send a request to that url and Payum does the rest.
Make sure the token factory is passed to a gateway object and later is injected to capture action object. Leave the notification_url field empty and Payum will generate a new one.
use your own url as notification one and add there all the info you need (as a query string). I wouldn't recommend it since you expose sensitive data and once could try to exploit it.
I solved it this way by appending ?trx=-TRANSACTION- with success and notification url and than in response i recieved Transaction id as parameter and later loaded TransactionData with that transactionId . Payum Token way wasn't working for me ! Obiously had to use its config key to create Payum/Sofort/Api isnstance,
REQUEST:
$args = [ 'config_key' => $sofortConfigKey ];
$sofortPay = new Api($args);
// ?trx=-TRANSACTION- will append transacion ID as response param !
$params = [
'amount' => $coupon['price'],
'currency_code' => $coupon['currency'],
'reason' => $coupon['description'],
'success_url' => $successUrl.'?trx=-TRANSACTION-',
'abort_url' => $abortUrl.'?trx=-TRANSACTION-',
'customer_protection' => false,
'notification_url' => '_URL_'.'?trx=-TRANSACTION-',
];
$transactionParams = $sofortPay->createTransaction($params);
return $this->redirect()->toUrl($transactionParams['payment_url']);
RESPONSE:
$args = [ 'config_key' => $configKey ];
$sofy = new Api( $args );
$transNumber = $this->getRequest()->getQuery('trx');
$fields = $sofy->getTransactionData($transNumber);
Took help from API document. Payum documentation is worst. SOFORT API DOC
I have created a FB App that grants the following permissions from the user:
1. manage_pages
2. read_insights
By using the app, the user can create a new tab on a page and delete it when this is necessary.
Apart from that, I want to give the option to the user to see some basic stats regarding the page(s) that she creates the tab(s).
For example, I want to retrieve the page views for a certain page for a specific period.
In order to do this I used the following code:
$today = date("Y-m-d");
$until = strtotime($today);
$since = strtotime("2013-08-01");
$pageID = "123";
$page_info = $facebook->api("/$pageID?fields=access_token");
$access_token = $page_info['access_token'];
$params = array(
'access_token' => $access_token,
'since' => $since,
'until' => $until,
);
$insights = $facebook->api("/{$pageID}/insights/page_views/",
"GET",
$params
);
print_r($insights);
The problem is that the result is...somehow empty. More precisely, I receive the following:
Array
(
[data] => Array
(
)
[paging] => Array
(
[previous]=>https://graph.facebook.com/123/insights/page_views/since=1370059200&until=1375329600
[next]=>https://graph.facebook.com/123/insights/page_views/since=1380600000&until=1385870400
)
)
When I use, the same logic to receive insights for my app (without using $token in the $params array), I receive the right data.
In addition to that, I was wondering if there is a way to create charts with this data (directly from FB).
Thx,
Antonis
I managed to solve the problem.
The returning array was empty, because I forgot to check if the user is logged in through facebook...
Regarding the charts, I didn't find any solution directly from facebook, so I used the Charts.js plugin.
I've a problem in handling the big userid's of facebook and properly storing them into my database..
As the fql.query REST api is going to be deprecated ,I'm using the GRAPH API for getting the results of the FQL.
I want to get the list of my friends with sex,relationship_status .
The query i executed is
$allFriends = $facebook->api("/fql
?q=SELECT+uid,+name,+sex,+relationship_status+FROM+user+where+uid+in+
(SELECT+uid2+FROM+friend+WHERE+uid1+=$fbuid)"
);
I tried the above in the Graph API explorer and the result is something like this,
{
"data": [
{
"uid": 100003082853071,
"name": "Sam jones",
"sex": "male",
"relationship_status": null
}
]
}
Note the uid is returned as int, so whenever i print the array itself it has values like (1.34234422 +E03). So even json_encode for that array doesn't help.
But when i call the GRAPH API directly something like 'graph.facebook.com/1585213/friends' that returns the data as
{
"data": [
{
"name": "Vijay Kannan",
"id": "102937142343"
}
]
}
Note the id is returned as string..
Whenever I'm using the graph API call for FQL query, it returns the whole data as an 'Array' ,so the long big facebook uid's are transformed to a float like (1.34234422 +E03) .
How can i convert them into proper uid's and store/process them back.
I think the inconsistency of FQL and GRAPH API call should be also taken care by Facebook .. But i could not wait for that!!
Any ideas on this?
I tried most methods and after Google some more forums and facebook code list if found the following worked like a charm for me.
After i get the results from a FQL query i used the following line of code,
$friends = json_decode(preg_replace('/"uid":(\d+)/', '"uid":"$1"', $result),true);
// consider $result as the result rendered by the FQL query.
When i use the file_get_contents for a FB call you could have seen the error with error codes, so the best way to go with that is using CURL for all the FB API calls whenever necessary.
Please find the complete code i've used to get proper results,
$access_token = $facebook->getAccessToken();
$request_url ="https://graph.facebook.com/fql
?q=SELECT+uid,+name,+sex+FROM+user+where+uid+in+
(SELECT+uid2+FROM+friend+WHERE+uid1+=$fbuid)".
"&access_token=".$access_token;
$opts = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-3.1',
CURLOPT_CAINFO => /lib/fb_ca_chain_bundle.crt',
//replace the above path with proper path of the crt file
//in order to avoid the exceptions rendered by FB
//when we try to use CURL without proper certification file.
);
$opts[CURLOPT_URL] = $request_url;
if (isset($opts[CURLOPT_HTTPHEADER])) {
$existing_headers = $opts[CURLOPT_HTTPHEADER];
$existing_headers[] = 'Expect:';
$opts[CURLOPT_HTTPHEADER] = $existing_headers;
} else {
$opts[CURLOPT_HTTPHEADER] = array('Expect:');
}
$ch = curl_init();
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
if ($result === false) {
$e = new FacebookApiException(array(
'error_code' => curl_errno($ch),
'error' => array(
'message' => curl_error($ch),
'type' => 'CurlException',
),
));
curl_close($ch);
throw $e;
}
curl_close($ch);
$friends = json_decode(preg_replace('/"uid":(\d+)/','"uid":"$1"',$result));
I just to post this answers so it may help others until Facebook resolve this inconsistency.
There are two things very consistent about Facebook. They are: 1) changing their APIs at their whim without any headsup. 2) Inconsistency between graph and fql objects.
As you have indicated, the unquoted values returned from Facebook are always long's (aka big int, aka Int64). And the quoted values are string representations of the long value.
What it appears to me is that the $facebook->api call is munging the longs into floats. I'd suggest logging it as a bug with the $facebook->api team.
In the interim while they fix that bug, you can code your own code to do the HTTP post to the graph and parse the returned results. I don't encounter this issue with the C# API, nor with the Javascript API.
If youre using php (http://php.net/manual/en/function.sprintf.php):
printf("%14.0f", 1.00000145202E+14);
outputs:
100000145202000
Javascript:
parseFloat('1.00000145202E+14')
I have the following code:
$twitter = new Zend_Service_Twitter(array('username' => $this->site->twitter_username, 'accessToken' => $this->site->twitter_password));
$response = $twitter->account->verifyCredentials();
print_r($response);
$twitter->account->endSession();
My username is my Login Username on twitter, my $this->site->twitter_password is my Access Token (oauth_token)
Yet I get:
Zend_Rest_Client_Result Object ( [_sxml:protected] => SimpleXMLElement Object ( [request] => /account/verify_credentials.xml [error] => Could not authenticate you. ) [_errstr:protected] => )
I'm unsure where I'm going wrong, any ideas?
I recently blogged about this and have included some instructions that should get you going, let me know if you need any more pointers.
PHP Using Zend framework to display new tweets as KDE notifications
I have a web app that allows users to connect Facebook account with their account on my site. When the user decides to connect with Facebook, the app requests publish_stream and offline_access permissions, and then stores the Facebook uid and session_key for each user. All this works fine right now.
My problem is migrating to Facebook's new OAuth 2.0 system. I'd like to transform the session keys I have into access tokens. I followed these instructions and everything seemed to work fine; Facebook returned a bunch of access tokens. However, none of them work. When I try to go to a URL such as https://graph.facebook.com/me?access_token=TOKEN-HERE, I get an error that says "Error validating client".
What am I doing wrong?
Also, I'm under the impression that access tokens work just like session keys in that once I have one, I can use it forever (since I request offline_access permissions). Is that correct?
Update:
Below are the exact steps I took to convert a session key into an access token, along with the output I got. Hopefully that will help bring my problem to light.
Step 1: Convert Session Key to Access Token
Code:
$session_key = '87ebbedf29cc2000a28603e8-100000652996522';
$app = sfConfig::get('app_facebook_prod_api'); // I happen to use Symfony. This gets an array with my Facebook app ID and secret.
$post = array(
'type' => 'client_cred',
'client_id' => $app['app_id'],
'client_secret' => $app['secret'],
'sessions' => $session_key
);
$options = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => 'https://graph.facebook.com/oauth/exchange_sessions',
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
var_export(json_decode($result));
Output:
array (
0 =>
stdClass::__set_state(array(
'access_token' => '251128963105|87ebbedf29cc2000a28603e8-100000652996522|Dy8CcJzEX8lYRrJE9Xk1EoW-BW0.',
)),
)
Step 2: Test Access Token
Code:
$access_token = '251128963105|87ebbedf29cc2000a28603e8-100000652996522|Dy8CcJzEX8lYRrJE9Xk1EoW-BW0.';
$options = array(
CURLOPT_HEADER => 0,
CURLOPT_URL => 'https://graph.facebook.com/me?access_token=' . $access_token,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
var_export(json_decode($result));
Output:
stdClass::__set_state(array(
'error' =>
stdClass::__set_state(array(
'type' => 'OAuthException',
'message' => 'Error validating client.',
)),
))
From reading your post here is my understanding -
You are tranforming session keys into access keys for each user in your system and storing these keys.
You then test the key using your own page. (Graph.facebook.com/me etc...)
If this is the case
A) You cannot use another users key with your own key. Going to graph.facebook.com would only be valid for the user that the key belongs to and if they were logged in. So for example, if you have my access key you could visit http://graph.facebook.com/YOURID....) but for graph.facebook.com/me to work you would have to be logged in as me.
B) These keys expire every 3 hours (Or there abouts) so it may no longer be valid.
The Platform Upgrade Guide has a section about OAuth 2.0 which includes the instructions for exchanging a session_key for an access_token. You should use this if you already have stored session keys.
For new users, you should use one of the new SDKs or the OAuth2 flow directly which will give you an access token to begin with.