Replying to a private message as a Facebook page - php

I created a tool for our support team that gets all private messages from our +/- 70 Facebook fan pages for easy processing and not having to manually click through all the pages to check if there are new or unanswered messages.
This tool worked perfectly for a couple of months but recently we've been getting the following error when trying to send a reply on a private message:
[error] => Array
(
[message] => (#504) Invalid reply thread id
[type] => OAuthException
[code] => 504
)
My code is as follows:
$fb->setAccessToken('%access_token%');
$edge = 't_id.' . $thread['id'] . '/messages';
$result = $fb->api($edge, 'POST', array('message' => $message));
I use extended access tokens but just to be sure I renewed them all. The value in $thread['id'] is the value from 'thread_id' from querying FQL 'message' table.
I searched in the Facebook docs but it looks like they removed everything concerning this subject, which could imply they removed the functionality entirely.
They say something about a new messages system which they are rolling out on the thread reference page, but I can't find anything else about this subject. https://developers.facebook.com/docs/reference/api/thread/
EDIT:
As you can see in the comments the documentation can be found here: https://developers.facebook.com/docs/graph-api/reference/page/conversations
I just made a new page for testing and I can't seem to get a valid access token in the graph api exlorer for accessing the edge /{page-id}/conversations. I remember this has happened before when I was developing my tool. The same access tokens didn't work for a week and then suddenly started working again...

Related

PHP problems with Google Analytics E-commerce: theiconic/php-ga-measurement-protocol

I'm using the theiconic/php-ga-measurement-protocol package and have followed the exact steps as described in the readme, but for reasons I don't quite understand, half of the info does not show up in Google Analytics.
I'm using the following code:
use TheIconic\Tracking\GoogleAnalytics\Analytics;
$trackingID = 'xxxxxxx';
$order = 'obviously an object';
$deal = 'object';
$analytics = new Analytics();
// the Client ID just won't do anything
$analytics->setProtocolVersion('1')
->setClientId($order->gaClientID)
->setTrackingId($trackingID);
// this part works just fine
$analytics->setTransactionId($transactionID)
->setRevenue($order->getTotalPrice(false))
->setTax($order->getTaxCost())
->sendTransaction();
// here it's as if nothing happens
// Yes, it does loop over all the orderRules but it does not show up in Google Analytics
foreach ($order->getOrderRules() as $orderRule) {
$analytics->setTransactionId($transactionID)
->setItemName($deal->name)
->setItemCode($order->dealID)
->setItemCategory($deal->getDealCategoryName())
->setItemPrice($orderRule->getPrice())
->sendItem();
}
And I'm saving the ClientID with this JavaScript into a hidden input:
ga.getAll()[0].get('clientId')
So my issues are basically:
client ID does not work
Items do not appear in Google Analytics Ecommerce
Is there anything I am forgetting? I've had several people looking at it, not being able to find out where it's going wrong.
What I would do:
Enhanced e-commerce: replace your code which is for the old e-commerce with this code which is for enhanced e-commerce. Reason: new (enhanced) is backward compatible with the old and has lots more features, so 0 point of using old e-commerce. Reason 2: the enhanced e-commerce implementation seems "cleaner" in the sense that all the data is sent with 1 single hit at the end (->sendEvent();), whereas the old e-commerce first sends the transaction (->sendTransaction();) then later the products with separate hits (->sendItem();).
Debug: enable debug mode to find out if/why your hits are being rejected by the API.
With enhanced e-commerce it should be something like:
$analytics->setDebug(true)
->setEventCategory('Checkout')
->setEventAction('Purchase')
->sendEvent();
$debugResponse = $response->getDebugResponse();
print_r($debugResponse);
And you should get debug from the API that will look like this:
{
"hitParsingResult": [
{
"valid": false,
"hit": "GET /debug/collect?tid=fake\u0026v=1 HTTP/1.1",
"parserMessage": [
{
"messageType": "ERROR",
"description": "The value provided for parameter 'tid' is invalid. Please see ... for details.",
"parameter": "tid"
},
Filters: if your hits are not rejected by the API (once they are validated you have to remove the debug for them to be actually sent), I would look in GA to check if you don't have filters excluding your hits.
Quotas: although unlikely, I would also check if you haven't reached the API limits hence why your data isn't being collected.
BONUS: User-ID: if people making purchases have created a user account on your website, use your database ID as User ID: it will be easier to implement (you don't have to reverse engineer the Client ID, use your database ID), and will track the same user regardless of the browser/device used (Client ID is linked to the Cookie, so will be different for each device/browser the user uses, your database ID will always be the same as long as people log in with the same account)
I've tried the enhanced e-commerce again. I've done that before as well, but this time with the debug function on. The client ID gets send properly as seen in hitPersingResult[0]['hit']. But still nothing appears in google Analytics.
Also we're not hitting the limits. I've literally copy pasted the example and this is my response:
Array
(
[hitParsingResult] => Array
(
[0] => Array
(
[valid] => 1
[parserMessage] => Array
(
)
[hit] => /debug/collect?v=1&tid=UA-xxxxxxxx-11&cid=161460xxxx.xxxx180000&uid=161460xxxx.xxxx180000&ti=1802.48511-1518713633&ta=test%20affiliation&tr=206.95&tt=3.4623966942149&ts=0&pa=purchase&ec=Checkout&ea=Purchase&t=event&pr1id=2033&pr1nm=xxxxx&pr1br=brand&pr1ca=xxxxxx&pr1pr=xxx&pr1qt=1
)
)
[parserMessage] => Array
(
[0] => Array
(
[messageType] => INFO
[description] => Found 1 hit in the request.
)
)
)

I cannot refresh my Youtube API token and I don't understand the error returned

I'm new here and I thank in advance everyone that will help me.
I use Youtube API to collect comments in some videos. That's really important for me, because I have a system developed in PHP that collects public content of social media. I have an app in Google APIs and I can authenticate the account on my system using OAUTH. It works just fine.
However, this token expires after a few minutes. There is something in the API called refresh token, which is returned after the first authentication. It must be used exactly to refresh my token and keep me accessing the API. Some days ago this resource stopped working. I'm not able to refresh my token anymore and I don't understand the error in the JSON they return to me.
I try to renew the token using cUrl:
public function renewToken() {
$url = 'https://accounts.google.com/o/oauth2/token';
$params = array(
'body' => array(
'client_id' => self::CLIENT_ID,
'client_secret' => self::CLIENT_SECRET,
'refresh_token' => $this->refresh_token,
'grant_type' => 'refresh_token',
),
);
$return = $this->curl->post($url, $params);
if($this->curl->http_code==200)
....
It was working until one or two weeks ago. Then it just stopped I can't seem to find why. The only error message returned by the API says:
{
"error" : "invalid_request"
}
I created a new application on Google APIs Console, got the client ID and secret and the Key, changed them in my code and the result is the same. I have the faintest clue of what if going on. Is it happening to somebody
The OAuth2.0 documentation on Google Developers was last changed 2 days ago (as of today, October 8th, 2016), on October 6th (see bottom of page). I can only assume that they recently made some changes to the workflow, which would explain why your app stopped working all of a sudden.
I noticed, for example, that the documented URL for renewing the token is not https://accounts.google.com/o/oauth2/token, as used by you, but rather https://www.googleapis.com/oauth2/v4/token (see section "Using a refresh token"). Please try with this URL.

Can't post new track via PHP Soundcloud API

I'm in a bit of a pickle here. I developped a Wordpress plugin that helps my site publish sounds to soundcloud directly from the WP back-office. The site has been live for about a year, and I have had no problems until now.
When uploading a track, I get a 'Fatal error: Uncaught exception 'Services_Soundcloud_Invalid_Http_Response_Code_Exception' with message 'The requested URL responded with HTTP code 422.'
I checked if nothing on my code had changed, and it hasn't, the request seems properly formed. Here is the bit of code:
$soundcloud->setAccessToken($_POST['access_token']);
$mytrack = array(
'track[title]' => $_POST["audioname"],
'track[asset_data]' => $_FILES["audiofile"]["tmp_name"]
);
$track = json_decode($soundcloud->post('tracks', $mytrack));
Any idea what could be wrong? I have a Pro Unlimited account, so I can't have reached a quota, can I? Other functions used through the API work properly...
If you are getting a 422 http code. That's 'Unprocessable entity' error acording to the docs. What it probably mean is that you data structure is wrong.
I don't know the php library you're using but I invite you to try out my own opensource library. https://github.com/njasm/soundcloud . Check the readme. You have an example on how to upload tracks.

Evernote Integration With PHP

I have successfully done with the authentication of Evernote with PHP.
And I have got this response.
Array ( [oauth_token] => S=s1:U=6316e:E=144fcfdfdb9:C=13da54cd1ba:P=185:A=maheshchari-2599:V=2:H=6da806fe92b9289cf0334f04e2afdc55 [oauth_token_secret] => [edam_shard] => s1 [edam_userId] => 405870 [edam_expires] => 1395813907897 [edam_noteStoreUrl] => https://sandbox.evernote.com/shard/s1/notestore [edam_webApiUrlPrefix] => https://sandbox.evernote.com/shard/s1/ )
Now, I want the list of notebooks of the user which has been authenticated with evernote.
I have done a lot of research online but I couldnt find any thing which helps, I have came to know that guid is necessary to get the list of notebooks.
From where I can find that? And how can i access the notestore and userstore?
How can i call the functions of notestore and userstore to fetch the data of user's account and user's notes in php?
Thanks in Advance.
Using the Evernote SDK for PHP, you can list notebooks like the way below:
$client = new Client(array('token' => $authToken));
$noteStore = $client->getNoteStore();
$notebooks = $noteStore->listNotebooks();
All the API references can be found here.
Also, you shouldn't make your token public. Please make sure your token string you put can't be used any more. If you need more help on this, you can get supports from Evernote developer support.
https://github.com/evernote/evernote-sdk-php
go to this link and download this zip then go to sample folder then go to client folder and run EDAMTest.php page.
and add authtoken.

hotmail: user authentication and contact retrieval with PHP

I am trying to write a PHP script that will allow me to do two things:
Allow users to use their Hotmail (I think its called 'Live' now?) account to authenticate themselves to a website
Retrieve an authenticated users contact list from Hotmail.
I have trawled the internet for the past 6 hours, looking for at least a working example that I can modify/extend to do the above two things. There are several dozens similar questions asked here on SO for example - NONE of the proffered answers work any more (admittedly, some of the questions were a few years old).
I tried the Microsoft site and downloaded the latest version of their API which seems to evolve at a rather alarming rate. I finally managed to track down an API which has not been deprecated (yet?).
I followed the instructions and when I attempted to authenticate, I was rewarded with the following mesage, for my efforts:
We're unable to complete your request
Windows Live ID is experiencing technical difficulties. Please try again later.
I immediately tried the online version of the demo and perhaps unsurprisingly, that worked like a charm.
As an aside, I managed to implement the same functionality for Yahoo and GMail, using their OPEN APIs, under an hour each. Now, it is possible that my unmitigated hatred of all things proprietary (sorry make that Microsoft), is causing me to lose the plot a little here.
Has anyone ACTUALLY (in 2012) managed to get a working sample in PHP that allows:
Hotmail (live?) user authentication
Hotmail user contact email retrieval
If you have, a code snippet, or a link to where I can find such a snippet would be very useful, as I have so far, wasted a whole afternoon trying to work the Microsoft Live API via PHP.
PS: No, I'm not interested in OpenInviter, its broken.
i wrote my own oauth library based around a single array for each service provider. this array contains all of the data required to perform authentication and retrieve user data. the array i use for msdn (ie. hotmail, outlook, xbox, msn) is:
$msdn = array
(
'oauth_version' => '2',
'oauth_method' => 'GET',
'redirect_user_params' => array
(
'url' => 'https://oauth.live.com/authorize',
'response_type' => 'code',
'http_params' => array
(
'url',
'client_id',
'redirect_uri',
'response_type',
'scope',
'state'
)
),
'obtain_access_token_params' => array
(
'url' => 'https://oauth.live.com/token',
'grant_type' => 'authorization_code',
'http_params' => array
(
'url',
'client_id',
'client_secret',
'code',
'grant_type',
'redirect_uri',
'scope'
)
),
'scope' => 'wl.signin wl.basic',
'obtain_user_data_params' => array
(
'url' => 'https://apis.live.net/v5.0/me',
'http_params' => array
(
'url',
'access_token',
'scope'
)
),
'client_id' => 'xxxxx', // = oauth_consumer_key in oauth 1.0 lingo
'client_secret' => 'xxxxxxxxxxxxxxx',
'readme_url' => 'http://msdn.microsoft.com/en-us/library/live/hh243647.aspx'
);
the parameters for each of the three oauth stages (ie "redirect user", "obtain access token" and "obtain user data") are in the http_params arrays. in the case of msdn these parameters end up in the query query string of the url that i send out with curl (since msdn only accepts GET, not POST).
i haven't tried retrieving the user's contact address book, but this would just be a case of extending the scope element with whatever extra information you require (documented here http://msdn.microsoft.com/en-us/library/live/hh243646.aspx). as you can see from the http_params arrays, the scope parameter is used in each of the three oauth stages.
Try out a Hotmail/MSN/Live import on the CloudSponge test drive to see if that's the user experience you're hoping for.
If it works for you, you can use our widget or our API. If you want to use the API, we have a PHP wrapper already written for your convenience.
Please confirm your callback url is with http:// if you only put www.domain.com then get this issue..

Categories