You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
returnmakeApiCall( url, endpointParams, 'GET' ) # make the api call
100
+
101
+
params=getCreds() # get creds from defines
102
+
103
+
params['media_type'] ='IMAGE'# type of asset
104
+
params['media_url'] ='https://justinstolpe.com/sandbox/ig_publish_content_img.png'# url on public server for the post
105
+
params['caption'] ='This image was posted through the Instagram Graph API with a python script I wrote! Go check out the video tutorial on my YouTube channel.'
106
+
params['caption'] +="\n."
107
+
params['caption'] +="\nyoutube.com/justinstolpe"
108
+
params['caption'] +="\n."
109
+
params['caption'] +="\n#instagram #graphapi #instagramgraphapi #code #coding #programming #python #api #webdeveloper #codinglife #developer #coder #tech #developerlife #webdev #youtube #instgramgraphapi"# caption for the post
110
+
111
+
imageMediaObjectResponse=createMediaObject( params ) # create a media object through the api
112
+
imageMediaObjectId=imageMediaObjectResponse['json_data']['id'] # id of the media object that was created
113
+
imageMediaStatusCode='IN_PROGRESS';
114
+
115
+
print( "\n---- IMAGE MEDIA OBJECT -----\n" ) # title
116
+
print( "\tID:" ) # label
117
+
print( "\t"+imageMediaObjectId ) # id of the object
118
+
119
+
whileimageMediaStatusCode!='FINISHED' : # keep checking until the object status is finished
120
+
imageMediaObjectStatusResponse=getMediaObjectStatus( imageMediaObjectId, params ) # check the status on the object
121
+
imageMediaStatusCode=imageMediaObjectStatusResponse['json_data']['status_code'] # update status code
122
+
123
+
print( "\n---- IMAGE MEDIA OBJECT STATUS -----\n" ) # display status response
124
+
print( "\tStatus Code:" ) # label
125
+
print( "\t"+imageMediaStatusCode ) # status code of the object
126
+
127
+
time.sleep( 5 ) # wait 5 seconds if the media object is still being processed
128
+
129
+
publishImageResponse=publishMedia( imageMediaObjectId, params ) # publish the post to instagram
130
+
131
+
print( "\n---- PUBLISHED IMAGE RESPONSE -----\n" ) # title
132
+
print( "\tResponse:" ) # label
133
+
print( publishImageResponse['json_data_pretty'] ) # json response from ig api
134
+
135
+
params['media_type'] ='VIDEO'# type of asset
136
+
params['media_url'] ='https://justinstolpe.com/sandbox/ig_publish_content_vid.mp4'# url on public server for the post
137
+
params['caption'] ='This video was posted through the Instagram Graph API with a python script I wrote! Go check out the video tutorial on my YouTube channel.'
138
+
params['caption'] +="\n."
139
+
params['caption'] +="\nyoutube.com/justinstolpe"
140
+
params['caption'] +="\n."
141
+
params['caption'] +="\n#instagram #graphapi #instagramgraphapi #code #coding #programming #python #api #webdeveloper #codinglife #developer #coder #tech #developerlife #webdev #youtube #instgramgraphapi"# caption for the post
142
+
143
+
videoMediaObjectResponse=createMediaObject( params ) # create a media object through the api
144
+
videoMediaObjectId=videoMediaObjectResponse['json_data']['id'] # id of the media object that was created
145
+
videoMediaStatusCode='IN_PROGRESS';
146
+
147
+
print( "\n---- VIDEO MEDIA OBJECT -----\n" ) # title
148
+
print( "\tID:" ) # label
149
+
print( "\t"+videoMediaObjectId ) # id of the object
150
+
151
+
whilevideoMediaStatusCode!='FINISHED' : # keep checking until the object status is finished
152
+
videoMediaObjectStatusResponse=getMediaObjectStatus( videoMediaObjectId, params ) # check the status on the object
153
+
videoMediaStatusCode=videoMediaObjectStatusResponse['json_data']['status_code'] # update status code
154
+
155
+
print( "\n---- VIDEO MEDIA OBJECT STATUS -----\n" ) # display status response
156
+
print( "\tStatus Code:" ) # label
157
+
print( "\t"+videoMediaStatusCode ) # status code of the object
158
+
159
+
time.sleep( 5 ) # wait 5 seconds if the media object is still being processed
160
+
161
+
publishVideoResponse=publishMedia( videoMediaObjectId, params ) # publish the post to instagram
162
+
163
+
print( "\n---- PUBLISHED IMAGE RESPONSE -----\n" ) # title
164
+
print( "\tResponse:" ) # label
165
+
print( publishVideoResponse['json_data_pretty'] ) # json response from ig api
166
+
167
+
contentPublishingApiLimit=getContentPublishingLimit( params ) # get the users api limit
168
+
169
+
print( "\n---- CONTENT PUBLISHING USER API LIMIT -----\n" ) # title
170
+
print( "\tResponse:" ) # label
171
+
print( contentPublishingApiLimit['json_data_pretty'] ) # json response from ig api
0 commit comments